필터 지우기
필터 지우기

Accessing data from structures

조회 수: 2 (최근 30일)
laurie
laurie 2015년 8월 12일
답변: Uladzimir 2015년 8월 12일
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)

답변 (2개)

Star Strider
Star Strider 2015년 8월 12일
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

Uladzimir
Uladzimir 2015년 8월 12일
[~,maxind] = max(Pop.B);
Pop.A(maxind)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by