Matlab while loop/array help.

4 views (last 30 days)
Mary
Mary on 13 Feb 2012
so this is what i have to do. i have an array for example
n = [1 2 3 4 0.555 0.25 7 8];
i have to find the minimum of this array but i have to exclude the 0.555 value since this is an anomaly and then find the minimum after this value has been excluded. the data I am actually working with is much bigger.
does anybody know how to write a while loop for this problem in matlab?
this is what i have tried but it is not giving me the correct answer (i have used a if loop int this one:
clear
clc
n = [1 2 1.5 0.5 0.25 3 4 5 6 7];
k = 1:7;
m = min(n);
for a = 1:7
if(n(a) > m)
x = min(n(a))
%newMin= min(newArray);
end
end
is there any way to do this using a while loop?
thank you, your help is much appreciated

Accepted Answer

Jonathan Sullivan
Jonathan Sullivan on 13 Feb 2012
Mary, there is no need for a while loop. You can do this simply by excluding the value you and, and then taking the min.
exclude_val = 0.555;
m = min(n(n ~= exclude_val));

More Answers (1)

Mary
Mary on 14 Feb 2012
thank you for your help!

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!