Create a function that takes an array as input, and returns the same array in reverse order of the input, as in the example behavior below. Do not use MATLAB’s fliplr() function. forwards = [5 6 7 8] reverse = reverseArray(forwards) disp(reverse) > > 8 7 6 5 function [output] = reverseArray(input)
Expert Answer
create a file named reversArray.m and paste given code into into it. (file name must be reversArray.m)
function [output] = reversArray(input)
output = [];
for i = 1:size(input,2)
output = [input(i),output];
end
end
Sample test:
octave:5> out = reverseArray([1,2,3,4])
out = 4 3 2 1
octave:6> out = reverseArray([5,6,7,8]) out = 8 7 6 5