find the minmum value in each column of a matrix

1 vue (au cours des 30 derniers jours)
kurdistan mohsin
kurdistan mohsin le 11 Avr 2022
Commenté : Mathieu NOE le 12 Avr 2022
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

Réponse acceptée

Rik
Rik le 11 Avr 2022
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

Plus de réponses (1)

Mathieu NOE
Mathieu NOE le 11 Avr 2022
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
  2 commentaires
kurdistan mohsin
kurdistan mohsin le 11 Avr 2022
thanks alot
Mathieu NOE
Mathieu NOE le 12 Avr 2022
my pleasure !

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by