important

1 次查看(过去 30 天)
Nasir Qazi
Nasir Qazi 2012-5-4
disp('1 for comp1');disp('2 for comp2');disp('3 for comp3');disp('4 for comp4');disp('5 for comp5');disp('6 for comp6');disp('7 for comp7');
% in the above components I want to select components
nc = input('Input the components')
% for example nc = 3 , now after giving this each component has a value of a variable Tc, Pc, w associated with it , how can I assign particular variable values after selecting my components
  2 个评论
Walter Roberson
Walter Roberson 2012-5-4
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
Walter Roberson
Walter Roberson 2012-5-4
Please use titles that give an indication of the content of the question being asked. I looked back over the Questions that you have asked, and you have often used titles that do not give any indication of the subject area. People tend to skip over Questions that have meaningless titles.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2012-5-4
Use "switch", or use a table of initial values that you index into.
  2 个评论
Nasir Qazi
Nasir Qazi 2012-5-4
% I did but I want it to assign the value of Tc according to the ordering of selecting my components like I did below but it doesn't select the values according to the error
disp('1 for CH4');disp('2 for CO2');disp('3 for N2');
nc =input('components');
if nc > 5
disp('Too Many component')
break
end
for i=1:nc
c(i)=input('c');
switch c(i)
case {c(1)==1}
Tc(1,1) = 190;
case {c(2)==2}
Tc(1,2) = 120;
case {c(3)==3}
Tc(1,3) = 890;
case {c(4)==4}
Tc(1,4) = 1210;
case {c(5)==5}
Tc(1,5) = 1990;
otherwise
disp('enter the comp')
end
end
Walter Roberson
Walter Roberson 2012-5-4
switch c(i)
case 1
Tc(1,i) = 190;
case 2
...

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by