MATLAB: How to use switch case function to get decimal numbers

MATLABswitch case

M% Temperatur_C = [13,6169 14,5432 15,2356 17,2456 18,1887 19.9874 21,2765]
% Coeff -30C -20 -10 0 10 20 30 40 50
% nT 1.8 1.8 1.4 1.1 1.1 1 0.9 0.9 0.8
for A=1:(a-1)
switch (Temperatur_C(1,A))
case num2cell(-10.0:0)
disp('nT=1.4')
nT_NO(1,A) = 1.4;
case num2cell(0.1:4.99)
disp('nT=1.1')
nT_NO(1,A) = 1.1;
end
If I use round command I get the answer but that's not right for me because I want to be able to get the specific temperature not rounded.For example if the temp is 18,1887 it gets it as 20.
for A=1:(a-1)
switch round(Temperatur_C(1,A))
case num2cell(-10.0:0)
disp('nT=1.4')
nT_NO(1,A) = 1.4;
case num2cell(0.1:4.99)
disp('nT=1.1')
nT_NO(1,A) = 1.1;
end

Best Answer

I'm curious if you understand what that num2cell(-10.0:0) actually do in the case statement? If you don't and it's something you've been given by someone else don't use it.
It's not clear exactly what you're trying to do. I suspect it is this (minus the disps which are a bit pointless):
Breakpoints = [-Inf -30 -10 0 20 30 50 +Inf];
nT_Values = [NaN 1.8 1.4 1.1 1 0.9 0.8];
whichcolumn = discretize(Temperatur_C, Breakpoints);
nT_NO = nT_Values(whichcolumn);
%and if you want the equivalent to disp:
%celldisp(compose('nT=%g', nT_NO));
You can't do what you were trying to do with switch statements, you could do it with if...elseif
for idx = 1:numel(Temperature_C)
if Temperatur_C(idx) >= -30 & Temperatur_C(idx) < -10
nT_NO(idx) = 1.4;
elseif Temperatur_C(idx) >= -10 & Temperatur_C(idx) < 0
nT_NO(idx) = 1.1;
elseif ...etc
end
end
As you can see, using discretize is much simpler.