I don't know why it keeps saying illegal use of "case"
1 view (last 30 days)
Show older comments
% P2
function k = ThCond(T,alloyname)
%Input arguments:
%K is the temperature as an array
%The alloy name associated with the temperature array
%Outputs:
%k, the thermal conductivity as an array the same size as T
switch ThCond
case {'Al1'}
if 298<=T && T<=840
k=149.7+0.0809*T-(1*10^-4)*T^2
else
('Error in code')
case {'Al2'}
if 298<=T && T<=773
k=76.64+0.2633*T-(2*10^-4)*T^2
else
Error('error in code')
case {'Al3'}
if 298<=T && T<=890
k=124.7+0.56*T+(1*10^-5)*T^2
else
Error('error in code')
case {'Cu1'}
if 100<=T && T<=1200
k=453.9-0.1054*T
else
Error('error in code')
case {'Cu2'}
if 460<=T && T<=1188
k=140.62+(112.14*10^-4)*T
else
Error('error in code')
case {'Cu3'}
if T<=1443
k=16.041+(438.9*10^-4)*T
else
Error('error in code')
case {'St1'}
if 400<=T && T<=1000
k=76.63-0.0459*T
else
Error('error in code')
case {'St2'}
if 298<=T && T<=1573
k=6.31+(27.2*10^-3)*T-(7.0*10^-6)*T^2
else
Error('error in code')
case {'St3'}
if T<=1727
k=20+(61.5*10^-4)*T
else
Error('error in code')
end
end
0 Comments
Answers (2)
Stephen23
on 3 May 2018
Edited: Stephen23
on 3 May 2018
It looks like Python code, because all of the if statements are missing the end (which is required by MATLAB):
if 298<=T && T<=840
k=149.7+0.0809*T-(1*10^-4)*T^2
else
('Error in code')
end % <---- you are missing this everywhere!
This is a good example of why it is important to read the documentation for every function and operator, no matter how trivial it might seem.
0 Comments
Star Strider
on 3 May 2018
If I understand what you want to do, using:
switch alloyname
would probably produce the desired behaviour.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!