Clear Filters
Clear Filters

max row vector in matrix

3 views (last 30 days)
I'm doing a code to calculate marks for teams and to display them as a table after that i want to display the winner by getting the maximum marks (which is a row vecter in a matrix)
n=input('how many teams: ') ;
S = struct ;
if n>0
for i=1:n
S(i).Team = input(['team "' num2str(i) '" name : '] , 's');
a = input(['team "' num2str(S(i).Team) '" 1st throw: ']);
b = input(['team "' num2str(S(i).Team) '" 2nd throw : ']);
c = input(['team "' num2str(S(i).Team) '" 3rd throw : ']);
d = input(['team "' num2str(S(i).Team) '" 4th throw : ']);
e = input(['team "' num2str(S(i).Team) '" 5th throw : ']);
S(i).Marks = [a b c d e];
S
r=1:n;
end
A=struct2table(S)
c=A(:,2);
w=table2array(c);
else
disp("no teams")
end

Accepted Answer

Benjamin Thompson
Benjamin Thompson on 28 Jan 2022
A =
3×2 table
Team Marks
___________ _________________________
{'Cubs' } 4 12 6 7 9
{'Reds' } 7 4 2 7 3
{'Yankees'} 5 9 3 6 8
>> w
w =
4 12 6 7 9
7 4 2 7 3
5 9 3 6 8
>> max(w)
ans =
7 12 6 7 9
>>
  2 Comments
Faisal Al-Wazir
Faisal Al-Wazir on 29 Jan 2022
yes you can see it's wrong
Faisal Al-Wazir
Faisal Al-Wazir on 29 Jan 2022
it should be 4 12 6 7 9

Sign in to comment.

More Answers (0)

Categories

Find more on WLAN Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!