Find max value in each column of a 6x5 matrix without using built in matlab functions.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Josh Rudbart
il 17 Apr 2019
Commentato: Josh Rudbart
il 17 Apr 2019
My command window for one of the columns is underneath code and i just cannot figure out how to get the max value in each column. i have gotten down to having columnval= each number in each column but when cant figure out how to go about getting the max because what ive tried ends up giving me same maxval for every columnval.
A=randi(100,6,5)
for columns=1:5
column=A(:,columns)
maxvalue=0;
for columndown=1:6
columnval=column(columndown,:)
if columnval>maxvalue
maxvalue=columnval;
end
end
end
column =
6
18
67
34
90
12
columnval =
6
columnval =
18
columnval =
67
columnval =
34
columnval =
90
columnval =
12
Risposta accettata
Mauro Fusco
il 17 Apr 2019
Hi,
based on your code a few modifications will make it work:
A=randi(100,6,5)
maxvalue = zeros(1,5);
for columns=1:5
column=A(:,columns);
for columndown=1:6
columnval=column(columndown);
if columnval>maxvalue(columns)
maxvalue(columns)=columnval;
end
end
end
maxvalue %show the row with max value for each column :-)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calendar in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!