Given the code :
function[p] = addMoreCells(v,n)
% adding zero at the beginning
k = length(v);
if (k ~= n)
p = zeros(1,n);
for m = (n-1):-1:(n-k)
p(m+1) = v(k-(n-m-1));
end
else
p = v;
end
end
I build a new array with n cells and put there 0 , later I add the other cells from v .
It there a built in command that can perform that instead ?
Thanks
The code you have now is really overcomplicating it. Always try to avoid for loops in Matlab, it is way more efficient if you can do operations on vectors rather than on elements.
How about something like this? You can easily turn it into a function: