Have values display based on user input

3 views (last 30 days)
I am trying to have my function to prompt the user to enter a word and have values display based on the word entered. I am not sure exactly how do I move foward from this?
function [T_mp,rho,cp,k,alpha] = Material_Properties(MN)
T_mp_vec = [1406 2192 693 2125]';
rho_vec = [19070 6100 7140 6570]';
cp_vec = [116 489 389 278]';
k_vec = [27.6 30.7 116 22.7]';
a_vec = [12.5 10.3 41.8 12.4]'*1e-6;
if input('Uranium')
t_mp = T_mp_vec(1)
rho = rho_vec(1)
cp = cp_vec(1)
k = k_vec(1)
alpha = a_vec(1)
if input('Vanadium')
t_mp = T_mp_vec(2)
rho = rho_vec(2)
cp = cp_vec(2)
k = k_vec(2)
alpha = a_vec(2)
end
end
end
  2 Comments
Rik
Rik on 2 Dec 2020
Edited: Rik on 2 Dec 2020
Unfortunately for Forza, anyone can follow this guide to retrieve question content that has been edited away from the Google cache:
Have values display based on user input
I am trying to have my function to prompt the user to enter a word and have values display based on the word entered. I am not sure exactly how do I move foward from this?
function [T_mp,rho,cp,k,alpha] = Material_Properties(MN)
T_mp_vec = [1406 2192 693 2125]';
rho_vec = [19070 6100 7140 6570]';
cp_vec = [116 489 389 278]';
k_vec = [27.6 30.7 116 22.7]';
a_vec = [12.5 10.3 41.8 12.4]'*1e-6;
if input('Uranium')
t_mp = T_mp_vec(1)
rho = rho_vec(1)
cp = cp_vec(1)
k = k_vec(1)
alpha = a_vec(1)
if input('Vanadium')
t_mp = T_mp_vec(2)
rho = rho_vec(2)
cp = cp_vec(2)
k = k_vec(2)
alpha = a_vec(2)
end
end
end

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Dec 2020
function [T_mp,rho,cp,k,alpha] = Material_Properties(MN)
T_mp_vec = [1406 2192 693 2125]';
rho_vec = [19070 6100 7140 6570]';
cp_vec = [116 489 389 278]';
k_vec = [27.6 30.7 116 22.7]';
a_vec = [12.5 10.3 41.8 12.4]'*1e-6;
material = input("Pick a card, any card!", 's');
switch lower(material)
case 'uranium':
t_mp = T_mp_vec(1);
rho = rho_vec(1);
cp = cp_vec(1);
k = k_vec(1);
alpha = a_vec(1);
case 'vanadium'
t_mp = T_mp_vec(2);
rho = rho_vec(2);
cp = cp_vec(2);
k = k_vec(2);
alpha = a_vec(2);
otherwise
error('You were not supposed to pick THAT card!');
end
end
By the way, what is the purpose of the MN input the user can pass in?
  2 Comments
Forza
Forza on 2 Dec 2020
Edited: Forza on 2 Dec 2020
[REDACTED]
Walter Roberson
Walter Roberson on 2 Dec 2020
User had posted,
"So MN is just like a place holder, kind of. What im trying to do it have the code ask the user to enter between Uranium or vanadium, and output values based on either of the choices. I hope this made more sense."

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!