Help finding max value of each column in random 6 X 5 matrix (without using built in functions)

1 次查看(过去 30 天)
im getting close but need some help. code worked for last 2 columns but not for first couple. gave me multiple of what looked like max and min number from them. i posted the command window underneath with what its outputting. Again, i need the max value in each column without using built in functions.
A=randi(100,6,5)
for column=1:5
columns=A( :,column)
cmax=-inf;
for row=1:6
rows=columns(row, :);
if rows>cmax
cmax=rows;
end
disp(cmax)
end
end
A =
9 49 53 37 10
27 58 24 99 27
81 24 49 4 34
3 46 63 89 68
93 97 68 92 14
74 55 40 80 73
columns =
9
27
81
3
93
74
9
27
81
81
93
93
columns =
49
58
24
46
97
55
49
58
58
58
97
97
columns =
53
24
49
63
68
40
53
53
53
63
68
68
columns =
37
99
4
89
92
80
37
99
99
99
99
99
columns =
10
27
34
68
14
73
10
27
34
68
68
73

回答(1 个)

Matt J
Matt J 2019-4-10
Can't you just do
max(A,[],1)
min(A,[],1)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by