So I got these instructions:
Write a function flipvec that will receive one input argument. If the input argument is a row vector, the function will reverse the order and return a new row vector. If the input argument is a column vector, the function will reverse the order and return a new column vector. If the input argument is a matrix or scalar, the function will return the input argument unchanged.
So i wrote this code:
function out = flipvec(~) out = input('Enter a column or row vector, a matrix or a scalar: \n'); m = ismatrix(out); s = isscalar(out); CR = isvector(out(1,:)); if s == 1 disp(out) elseif s ==0 if m == 1 disp(out) elseif m == 0 if CR == 1 newout = fliplr(out); disp(newout) elseif CR == 0 vecout = flipud(out); disp(vecout) else disp('Quit.') end end else disp('Quit.') clear end
These are some of the outputs I get when I call the function:
>> flipvecEnter a column or row vector, a matrix or a scalar: 3 3ans = 3>> flipvecEnter a column or row vector, a matrix or a scalar: 3 3ans = 3>> flipvecEnter a column or row vector, a matrix or a scalar: 3 3ans = 3>> flipvecEnter a column or row vector, a matrix or a scalar: [3; 5; 7] 3 5 7ans = 3 5 7 >> flipvecEnter a column or row vector, a matrix or a scalar: [3 5; 6 5; 9 10] 3 5 6 5 9 10ans = 3 5 6 5 9 10>> flipvecEnter a column or row vector, a matrix or a scalar: [2 4 5 6] 2 4 5 6ans = 2 4 5 6
I'm not sure why the function is not fliping the vectors or also displaying an "ans." Any suggestions?
Thank you!!
Best Answer