Have values display based on user input

3 ビュー (過去 30 日間)
Forza
Forza 2020 年 12 月 2 日
コメント済み: Rena Berman 2021 年 5 月 6 日
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 件のコメント
Rik
Rik 2020 年 12 月 2 日
編集済み: Rik 2020 年 12 月 2 日
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 2021 年 5 月 6 日
(Answers Dev) Restored edit

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 2 日
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 件のコメント
Forza
Forza 2020 年 12 月 2 日
編集済み: Forza 2020 年 12 月 2 日
[REDACTED]
Walter Roberson
Walter Roberson 2020 年 12 月 2 日
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."

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by