Help with For/If commands
1 次查看(过去 30 天)
显示 更早的评论
I am working on a project right now, and have a menu asking what a user would like to solve for. The menu corresponds to function handles, and in the function handles the variables can be used in more than 1. What i want to do is to have it run for variable A or B or C, and if it doesn;t have A B or C in it, it will stop and move to D E and F.
Here is what some of the code looks like :
(choice is the variable i assigned for the menu)
if choice == 1,4;6;7;8;10;11;
a=input ('What is the cross sectional area? ');
else
end
if choice ==2,3;5;6;
cl=input('What is the change in length? ');
else
end
0 个评论
采纳的回答
Junaid
2012-4-18
Use switches .. I hope it will solve your problem.
ex.
switch choice
case {1,4,6,7,8,10,11}
% your code here
case {2,3,5,6}
% your code here
end
更多回答(1 个)
Walter Roberson
2012-4-18
switch choice
case {2, 3, 4, 5, 6, 7}
%your code here
end
switch choice
case {8, 9, 11}
%your code here
end
If you prefer to use "if":
if ismember(choice, [1 4 6 7 8 10 11])
%your code here
end
if ismember(choice, [8, 9, 11])
%your code here
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scope Variables and Generate Names 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!