MATLAB: Location of non zeros

locationnonzeros

Hi there if I have a 100×1 matrix which has some zeros in it, how can i find the corresponding matrix of "locations" for all the cells which are non-zero.
Eg, 1, 3, 2, 0 , 2, 4, 1, 0 , 0
Output:
1, 2, 3, 5, 6, 7, ……

Best Answer

>> A=[ 1, 3, 2, 0 , 2, 4, 1, 0 , 0];
>> locations = find(A)
locations =
1 2 3 5 6 7