find is working in strange way

Hello I am trying to use the find to find number in array greater than 0.6 , but the behavior is strange
cluster_map=zeros(21,14);
[r c]=find(field>=0.6)
the length of the r is 20
cluster_map(r,c)=2;
[rr cc]=find(cluster_map == 2);
the length of rr is 40 !!! how this happen. I have attached the field array. thanks in advance

 Accepted Answer

r = [1 5 8]
c = [2 3 6]
x = zeros(10)
x(r,c) = 1
I'd guess what you want is to use sub2ind to use each combo of r and c once
x = zeros(10);
x(sub2ind(size(x),r,c)) = 1

6 Comments

Yes , it works with the sub2ind , it is strange that when i put the indices directly that it makes all combination between them . Thanks a lot.
It seems weird in this context. But consider this example:
x = zeros(5)
x(1:3,1:3) = 1
Would you expect the whole upper left corner to be ones, or just the upper left of the diagonal?
what if the
if true
x=zeros(10,10,2);
end
with the same r and c , how we can use the sub2ind for the third dimension? Thanks in advance
Fill the third-nth dimension with ones:
sub2ind(size(x),r,c,ones(size(r)))
it just fill x(r,c,1) , but still x(r,c,2). it looks like one need to do something like that
x(sub2ind(size(x),r,c,[1 1 1]))=3
x(sub2ind(size(x),r,c,[2 2 2]))=3
I donot know how to do that once.
May be something like that
for (i=1:2);x(sub2ind(size(x),r,c,[i i i]))=3;end

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!