Finding the maximum in a structure array
4 次查看(过去 30 天)
显示 更早的评论
How would I go about finding the maximum in a structure array as well as the corresponding data with that maximum value. For example, if the structure array provided data about the name, gender, and quiz grade, how would I found the maximum (highest) quiz grade and display the name and gender corresponding to that quiz grade?
0 个评论
采纳的回答
Image Analyst
2022-2-24
If strArray is your structure array (one structure per student), and quizGrade is the value for each structure, then to get all the grades for all the students into one vector you can do
allGrades = [strArray.quizGrade];
[maxGrade, indexOfMax] = max(allGrades);
studentWithHighestGrade = strArray(indexOfMax).studentName
2 个评论
Image Analyst
2022-2-25
Yes
structsToExtract = allGrades <= someValue; % someValue is less than maxGrade of course, otherwise you'd select everything.
newStruct = strArray(structsToExtract);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Standard File Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!