MATLAB: If a matrix contains 1’s and 0’s ,i would like to get only those 1’s and want to take avg values of those corresponding intensity values

image processing

If a matrix contains 1's and 0's ,i would like to get only those 1's and want to take avg values of those corresponding intensity values

Best Answer

Let a be your vector which have 0 and 1.
% get indices of 1
idx = a(a==1);
Let b be your intensity values corresponding to a.
% extract inentisity values of positions 1
b_1 = b(idx);