mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added a function to help reverse a string
This commit is contained in:
19
Reverse.m
Normal file
19
Reverse.m
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user