Determine the minimum value excluding zero

20 visualizaciones (últimos 30 días)
UTS
UTS el 10 de Mzo. de 2015
Comentada: UTS el 10 de Mzo. de 2015
A B
0.025 520
0.027 531
0.029 560
0.031 508
0.033 000
0.035 572
0.037 523
0.039 512
0.041 582
0.043 525
Hi, I am writing a program to determine the value of element A which is corresponding to the minimum value of element B. this value is not equal to zero [excluding zero]. The answer must be as:
M =
0.031
508
However, the written code
[MinB,Idx] = min(E(:,2)); Result = E(Idx,:)
gives this answer
M =
0.033
000
Could you please let me know the right code which is able to display the value of element A which is corresponding to smallest value of element B but it is not equal to zero
Thank you very much

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 10 de Mzo. de 2015
A= [0.025 520
0.027 531
0.029 560
0.031 508
0.033 000
0.035 572
0.037 523
0.039 512
0.041 582
0.043 525]
ii = A(:,2) > 0;
A2 = A(ii,:);
[M,i2] = min(A2(:,2));
out = [A2(i2,1),M];

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by