How to set a string as a CODE in script file?
显示 更早的评论
Legend CODE
Sum SU
Difference DI
How can I set this code(SU and DI) so that the user will only input these codes and will work the other lines?
回答(2 个)
Star Strider
2022-4-27
0 个投票
I am not certain what you are actually asking.
If you want the user to enter specific values and assign them in the code to specific variables, I prefer using the inputdlg function. That gives the script control of the variable assignments.
Walter Roberson
2022-4-28
validcodes = {'SU', 'DI'};
while true
choice = input('Enter a code: ', 's');
if strcmpi(choice, validcodes); break; end
fprintf('Bad code, try again\n');
end
But have you considered using menu() ?
类别
在 帮助中心 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!