Filter löschen
Filter löschen

max row vector in matrix

3 Ansichten (letzte 30 Tage)
Faisal Al-Wazir
Faisal Al-Wazir am 28 Jan. 2022
Kommentiert: Faisal Al-Wazir am 29 Jan. 2022
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

Akzeptierte Antwort

Benjamin Thompson
Benjamin Thompson am 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 Kommentare
Faisal Al-Wazir
Faisal Al-Wazir am 29 Jan. 2022
yes you can see it's wrong
Faisal Al-Wazir
Faisal Al-Wazir am 29 Jan. 2022
it should be 4 12 6 7 9

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu WLAN Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by