How do I select the Lowest of two values and select that as the best answer

Hi, I'm new to MATLAB and have just created a script to calculate two values using two different methods.
I have a percentage error for both:
P1=0.42 p2=0.94
How can I get matlab to select the lowest of the two values and then say to me:
The best method is method (P1 or P2) because it has the lowest percentage error.
If somebody could give me a point in the right direction I would be greatly appreciative.

 Accepted Answer

p1=0.42
p2=0.92
method={'p1','p2'}
[val,idx]= min([p1 p2])
disp(['the best method is ' method{idx}])

Categories

Products

Community Treasure Hunt

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

Start Hunting!