Azzera filtri
Azzera filtri

max row vector in matrix

3 visualizzazioni (ultimi 30 giorni)
Faisal Al-Wazir
Faisal Al-Wazir il 28 Gen 2022
Commentato: Faisal Al-Wazir il 29 Gen 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

Risposta accettata

Benjamin Thompson
Benjamin Thompson il 28 Gen 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 Commenti
Faisal Al-Wazir
Faisal Al-Wazir il 29 Gen 2022
yes you can see it's wrong
Faisal Al-Wazir
Faisal Al-Wazir il 29 Gen 2022
it should be 4 12 6 7 9

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su WLAN Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by