How can I limit input into the command window?

조회 수: 3 (최근 30일)
Femke R
Femke R 2022년 3월 25일
댓글: Star Strider 2022년 3월 25일
I have written an experiment where once in a while I have to input some numbers (1 and 2) into the command window to make the experiment continue. I am currently doing this using the input() function. However, the participant also has access to an instrument which writes letters to matlab. I want to limit the characters I can write into the command window to only include the numbers, so that the instrument doesn't interfere with my input. Checking for the right input after its been given will not work, as the instrument can continuiously send letters, making it impossible for me to write in just my numbers.
I currently have these lines of code, where I manually input whether I want to continue or abort after each block of trials, after which my input is evaluated.
while 1
cont=input(sprintf("do you want to continue with block %g? (1 for yes, 2 for no and abort): ",wrun));
%%% if you want to continue, go to next iteration (end while loop)
if cont ==1
break
%%% if you want to abort, make stop variable (end while loop)
elseif cont ==2
stop=1;
break
end

채택된 답변

Star Strider
Star Strider 2022년 3월 25일
I generally prefer to use the inputdlg fucntion, since it does not involve the Command Window.
If MATLAB is writing to the Command Window and that is causing problems using the input function, inputdlg could be a way to avoid that.
  댓글 수: 5
Femke R
Femke R 2022년 3월 25일
Questdlg solves my problem, thank you!
Star Strider
Star Strider 2022년 3월 25일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by