Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
How to display an error in an input for my function?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a function that calculates thermal conductivity, and I want to have the function display an error if the user inputs the wrong Alloy name. How would I do that. This is the code I have so far;
function k = ThCond(alloy,T) % T = input temperature
k = zeros(1,numel(T));
for a = 1:numel(T)
if (298 <= T(a)) && (T(a) <= 840) && strcmp(alloy,'Al2')
k(a) = 149.7 + 0.0809.*T(a) - (1.*10^(-4)).*(T(a).^2);
elseif (298 <= T(a)) && (T(a) <= 773)
k(a) = 76.64 + 0.2633.*T(a) - (2.*10^(-4)).*(T(a)^2);
end
if (293 <= T(a)) && (T(a) <= 890) && strcmp(alloy,'Al3')
k(a) = 124.7 + 0.56.*T(a) + (1*10^(-5)).*(T(a)^2);
end
if (100 <= T(a)) && (T(a) <= 1200) && strcmp(alloy,'Cu1')
k(a) = 453.9 - 0.1054.*T(a);
end
if (460 <= T(a)) && (T(a) <= 1188) && strcmp(alloy,'Cu2')
k(a) = 140.62 + (112.14.*10^(-4)).*T(a);
end
if T(a) <= 1443 && strcmp(alloy,'Cu3')
k(a) = 16.041 + (438.9.*10^(-4)).*T(a);
end
if (400 <= T(a)) && (T(a) <= 1000) && strcmp(alloy,'St1')
k(a) = 76.63 - 0.0459.*T(a);
end
if (298 < T(a)) && (T(a) < 1573) && strcmp(alloy,'St2')
k(a) = 6.31 + ((27.2.*10^(-3)).*T(a)) - (7.*10^(-6)).*(T(a).^2);
end
if T(a) <= 1727 && strcmp(alloy,'St3')
k(a) = 20 + (61.5.*10^(-4)).*T(a);
end
end
end
0 comentarios
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!