How to find the max number in a structure array?
2 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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} ) )
character(loc).Name
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!