Using find to compare matrices
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I have a matrix where the first column contains id's and the second some sort of information about thes id's, as an example such as below. What I want to do now, is to be able to say which information belongs to which id, for instance, for the example below, the id 1 has the "values" 5 and 9. So I would like to write code such that I could return for each id it's values. Now I have written that:
Y = [1,2,3,3,1; 5,6,7,8,9]'
U = unique(Y(:,1))
for i= 1:length(U)
[A B] = find(U(i)==Y(:,1))
end
Where the column with the 1,2,3,3,1 is storing these id's. Does that make any sense? What do I actually get returned in the [A B]?
Thanks a lot
0 Kommentare
Akzeptierte Antwort
Thomas
am 12 Dez. 2012
Bearbeitet: Thomas
am 12 Dez. 2012
You do not need find
Y = [1,2,3,3,1; 5,6,7,8,9]'
Y((Y(:,1)==1),2) % id =1
Y((Y(:,1)==2),2) % id=2
Y((Y(:,1)==3),2) % id=3
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!