Matlab while loop/array help.

4 Ansichten (letzte 30 Tage)
Mary
Mary am 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

Akzeptierte Antwort

Jonathan Sullivan
Jonathan Sullivan am 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));

Weitere Antworten (1)

Mary
Mary am 14 Feb. 2012
thank you for your help!

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by