How to find the max number in a structure array?

조회 수: 1 (최근 30일)
Kalpha.mc
Kalpha.mc 2020년 11월 9일
편집: Matt J 2020년 11월 9일
I am trying to get it to find the max lucky number but instead of diplaying the number i would i it to diplay the name witht the highest lucky number. Is there anyway i could get the matrix to diplay in the command window?( for favorite matrix)
like this [1 0
0 1]
character(1).Name = ('Elora');
character(1).Skills = {'Hugs' 'Hyponosis'};
character(1).Lucky_Number = ('7');
character(1).Favorite_Matrix = [1 0; 0 1];
character(2).Name = ('Garrett');
character(2).Skills = {'Crossbows' 'Trains'};
character(2).Lucky_Number = ('8');
character(2).Favorite_Matrix = [4 3; 2 1];
find(max(character(:).Lucky_Number))
  댓글 수: 2
per isakson
per isakson 2020년 11월 9일
Why is the value of character.Lucky_Number a character rather than a number? It adds to the complexity of the solution.
Kalpha.mc
Kalpha.mc 2020년 11월 9일
It don't have to be a character I just did it like that You can change it to (8) instead of ('8').

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 11월 9일
편집: Matt J 2020년 11월 9일
character(1).Name = ('Elora');
character(1).Skills = {'Hugs' 'Hyponosis'};
character(1).Lucky_Number = ('7');
character(1).Favorite_Matrix = [1 0; 0 1];
character(2).Name = ('Garrett');
character(2).Skills = {'Crossbows' 'Trains'};
character(2).Lucky_Number = ('8');
character(2).Favorite_Matrix = [4 3; 2 1];
[maxnum,loc] = max( str2double( {character.Lucky_Number} ) )
maxnum = 8
loc = 2
character(loc).Name
ans = 'Garrett'
  댓글 수: 3
Kalpha.mc
Kalpha.mc 2020년 11월 9일
That seems to diplay an error. So i am trying to get it to display the name of the person with the highest number. In this case it should display Garrett.
Matt J
Matt J 2020년 11월 9일
Fixed it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by