find the minmum value in each column of a matrix

조회 수: 2 (최근 30일)
kurdistan mohsin
kurdistan mohsin 2022년 4월 11일
댓글: Mathieu NOE 2022년 4월 12일
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