Have values display based on user input

6 Ansichten (letzte 30 Tage)
Forza
Forza am 2 Dez. 2020
Kommentiert: Rena Berman am 6 Mai 2021
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 Kommentare
Rik
Rik am 2 Dez. 2020
Bearbeitet: Rik am 2 Dez. 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 am 6 Mai 2021
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Dez. 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 Kommentare
Forza
Forza am 2 Dez. 2020
Bearbeitet: Forza am 2 Dez. 2020
[REDACTED]
Walter Roberson
Walter Roberson am 2 Dez. 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."

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by