MATLAB: Removing zeros from start of an array and inserting them at the end of same array

copyingMATLABmovingremovingrepmatreshaping

Let say I have an array
A = [ 0 0 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0 ]
I would like to know wheter is there any way to move starting four zeros to the end of same array A.
The result should be
Result = [ 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 ]
Now, in this example there were only four zeros. I do have arrays which have more than 4 zeros.
Thanks

Best Answer

Try this:
A = [0 0 0 0 1 2 3 4 5 6 7 8 9 0 0 0 0];
idx = find(A>0,1);
B = [A(idx:end),zeros(1,idx-1)]