find the minmum value in each column of a matrix

1 visualización (últimos 30 días)
kurdistan mohsin
kurdistan mohsin el 11 de Abr. de 2022
Comentada: Mathieu NOE el 12 de Abr. de 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

Respuesta aceptada

Rik
Rik el 11 de Abr. de 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

Más respuestas (1)

Mathieu NOE
Mathieu NOE el 11 de Abr. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by