필터 지우기
필터 지우기

Like to have input user command for cases

조회 수: 2 (최근 30일)
rockstar49
rockstar49 2023년 7월 10일
답변: Swapnil Tatiya 2023년 7월 12일
Like to ask user either enter 1,2,3 for a set of commands and then based off user unput, do a specific commands
for 1
( x=1, y=2, z=3)
for 2
(x=4, y=5, z=6)
for 3
(x=7,y=8,z=9)
then continue the code, so execute only a specific section.
Thanks.
  댓글 수: 2
rockstar49
rockstar49 2023년 7월 10일
이동: Cris LaPierre 2023년 7월 10일
Would switch-case be fine or can i use an IF statement saying if user input is 1, then do this etc?

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2023년 7월 10일
switch and case

Cris LaPierre
Cris LaPierre 2023년 7월 10일
You could use a switch-case statement
A case can be used for multiple criteria.
switch x
case {1,2,3}
%code
case {4,5,6}
%code
case {7,8,9}
%code
end

Swapnil Tatiya
Swapnil Tatiya 2023년 7월 12일
You could use the following code :
prompt='Enter your input';
user_input=input(prompt);
switch user_input
case{1,2,3}
%write code for what you'd like to perform
case{4,5,6}
%write code for what you'd like to perform
case{7,8,9}
%write code for what you'd like to perform
end
In the above code u can take the user_input and perform commands based on requirements
Hope this helps!

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by