Accessing data from structures
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
If I have a structure
Pop.A=[aa bb cc]
Pop.B=[ 2 4 6]
I need to find the highest value in Pop.B
max(cat(1,Pop.B))=6;
How do I extract the corresponding value in Pop.A??
Pop(3)
0 Kommentare
Antworten (2)
Star Strider
am 12 Aug. 2015
Address them as you normally would, using the second output (the index of the first occurrence of the maximum value) from the max function:
[aa,bb,cc] = deal(3,5,7); % Assign Variables
Pop.A=[aa bb cc];
Pop.B=[ 2 4 6];
[Bmax, Bidx] = max(Pop.B);
Amatch = Pop.A(Bidx)
Amatch =
7
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures 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!