Determine the minimum value excluding zero
20 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Andrei Bobrov
on 10 Mar 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];
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!