find the minmum value in each column of a matrix

1 次查看(过去 30 天)
i have the below matrix(d) and i want to find the minumum value of each column but that value must not equal to zero
d=
0 10.1164 0 0 0
11.4474 0 0 0 0
0 14.8026 0 0 0
0 0 0 0 17.4658
0 0 5.3885 0 0
13.7349 0 0 0 0
0 0 0 14.9564 0
0 0 10.7354 0 0
0 0 0 0 18.0236
0 0 0 17.2189 0

采纳的回答

Rik
Rik 2022-4-11
If you set all values of 0 to NaN, you can do this simply with the min function.
A=[ 0 10.1164 0 0 0
11.4474 0 0 0 0
0 14.8026 0 0 0
0 0 0 0 17.4658
0 0 5.3885 0 0
13.7349 0 0 0 0
0 0 0 14.9564 0
0 0 10.7354 0 0
0 0 0 0 18.0236
0 0 0 17.2189 0];
A(A==0)=NaN;
min(A)
ans = 1×5
11.4474 10.1164 5.3885 14.9564 17.4658

更多回答(1 个)

Mathieu NOE
Mathieu NOE 2022-4-11
hello
try this :
d=[ 0 10.1164 0 0 0;
11.4474 0 0 0 0;
0 14.8026 0 0 0;
0 0 0 0 17.4658
0 0 5.3885 0 0;
13.7349 0 0 0 0;
0 0 0 14.9564 0;
0 0 10.7354 0 0;
0 0 0 0 18.0236;
0 0 0 17.2189 0];
for ci = 1:size(d,2)
tmp = d(:,ci);
ind_non_zero = find(tmp>0);
[val(ci),ind] = min(tmp(ind_non_zero));
ind_final(ci) = ind_non_zero(ind);
end
val % min value (column direction)
ind_final % corresponding row position

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by