Find max value in each column of a 6x5 matrix without using built in matlab functions.

1 次查看(过去 30 天)
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

采纳的回答

Mauro Fusco
Mauro Fusco 2019-4-17
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 :-)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by