Find max value in each column of a 6x5 matrix without using built in matlab functions.
1 view (last 30 days)
Show older comments
Josh Rudbart
on 17 Apr 2019
Commented: Josh Rudbart
on 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
Accepted Answer
Mauro Fusco
on 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 :-)
More Answers (0)
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!