From 8ffe35966cfd4b7f611ccfb47066103bdfeee803 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Wed, 26 Sep 2018 01:06:00 -0400 Subject: [PATCH] Added a function to help reverse a string --- Reverse.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Reverse.m diff --git a/Reverse.m b/Reverse.m new file mode 100644 index 0000000..9a02df0 --- /dev/null +++ b/Reverse.m @@ -0,0 +1,19 @@ +function [rString] = Reverse(str) +%Reverse(string) +%This function Reverse the order of the elements in an array +%It was specifically designed for a string, but should work on other 1xX arrays +% + + if(nargin ~= 1) + error('That is not a valid number of arguments') + return; + end + + counter = size(str)(2); %Set the counter to the last element in string + %Loop until the counter reaches 0 + while(counter > 0) + %Add the current element of string to rString + rString(end + 1) = str(counter); + --counter; + end +end