Your first (inadvisable, numerically fragile, should-be-avoided) concept works for me:
for omega = 0.1:0.1:2;
switch omega
case 0.1
disp('one')
case 0.2
disp('two')
end
end
displays this in the command window:
Because of floating pont error in those numbers, this would be an extremely unreliable way to write code. Do NOT do this!
Your second method can be done quite easily, by simply thinking about the actual case value that you actually want switch to compare (hint: your case conditions are equal to true or false, but omega is not equal to true or false):
for omega = 0.1:0.1:2;
switch true
case abs(omega-0.1)<0.01;
disp('one')
case abs(omega-0.2)<0.01;
disp('two')
end
end
displays this in the command window:
Best Answer