Maximum and Minimum values of a field structure array
Mostra commenti meno recenti
Hi, I have structure array as shown in the image below. How can i find the maximum and minimum population with the corresponding state for the available data.

Thanks in advance.
Risposte (1)
Birdman
il 2 Apr 2020
%find max and min population
[Cmax,maxIdx]=max(AustralianStates.Population)
[Cmin,minIdx]=min(AustralianStates.Population)
%find corresponding state
AustralianStates.Name([minIdx maxIdx])
%find corresponding land area
AustralianStates.Land_Area([minIdx maxIdx])
8 Commenti
Rishitha Muchinthala
il 3 Apr 2020
Birdman
il 3 Apr 2020
Which version of MATLAB are you using? Can you also share your struct in a mat file?
Akira Agata
il 3 Apr 2020
I believe small modification is needed:
%find max population
[Cmax,maxIdx]=max([AustralianStates.Population]);
%find corresponding state
AustralianStates.Name(maxIdx)
%find corresponding land area
AustralianStates.Land_Area(maxIdx)
FYI, another possible solution to find max population is:
%find max population
T = struct2table(AustralianStates);
[Cmax,maxIdx]=max(T.Population);
Rishitha Muchinthala
il 3 Apr 2020
Birdman
il 3 Apr 2020
Can you try Akira's solution?
Rishitha Muchinthala
il 3 Apr 2020
Rishitha Muchinthala
il 3 Apr 2020
Rishitha Muchinthala
il 3 Apr 2020
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!