MATLAB: Reverse an array by for loop

for loopreverse

Hi i got this array : a=[1 2 3 4 5] and i want to reverse it by for loop so it will be a=[5 4 3 2 1]
Thanks

Best Answer

Why a for loop?
a = [1 2 3 4 5] ;
b = fliplr(a);
If you must with a for loop
for ii = 1:length(a)
b(ii) = a(length(a)-ii+1);
end