Have values display based on user input

6 visualizzazioni (ultimi 30 giorni)
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 Commenti
Rik
Rik il 2 Dic 2020
Modificato: Rik il 2 Dic 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
Rena Berman
Rena Berman il 6 Mag 2021
(Answers Dev) Restored edit

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 2 Dic 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 Commenti
Forza
Forza il 2 Dic 2020
Modificato: Forza il 2 Dic 2020
[REDACTED]
Walter Roberson
Walter Roberson il 2 Dic 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."

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by