I have a logical array of 0s an 1s. I would like to extract indices of all the cells with the value of 1, but without loosing information on columns. This gives a single column of indices.
idx = find(logical_array)
I tried for loop, but I'm not sure how to define my array before the for loop. Since the number of values varies between the columns, it generates a dimension mismatch error.
data = logical(randi(2,[10 3])-1);idx = zeros(x,y);for i = 1:y r_idx(:,i) = find(data(:,i));end
It works when I generate separate vectors and concatenate them with padcat function. But is there an easier way?
data = logical(randi(2,[10 3])-1); idx1 = find(data(:,1)); idx2 = find(data(:,2)); idx3 = find(data(:,3)); idx = padcat(idx1, idx2, idx3);
Best Answer