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

2 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by