The question is to write a function to reverse a vector so v=[1 2 3] becomes v= [3 2 1]
It must be recursive
So my idea how to write this function is start off with d=1 the last digit of w, the output, is equal to the first digit of v the input. so thats what I wrote. As the function develops d eventually equals the length of the original input symoblising the function has reached an end and it will return w. I just don't know how to keep d growing everytime, as currently with every time I recall the function d will rewrite itself to be 1. I think it has something to do with the base case but I don't know. I'm not looking for the answer on a plate but more like a discussion of someone talking me through it
function [w]=reversal(v)d=1e=length(v)w(end-d+1)=v(d)if d==ew=welse [w]=reversal(v) endend
Best Answer