필터 지우기
필터 지우기

Error with "input" function

조회 수: 15 (최근 30일)
lucie
lucie 2022년 10월 21일
댓글: lucie 2022년 10월 27일
Hello,
I am writing a quite simple code with MATLAB R2012b for an experiment and one of the first thing I want to do is to register the code of my 2 participants.
To do so, I wrote
>> codeA = input('Code of the first participant: ', 's');
>> codeB = input('Code of the second participant: ', 's');
When I run the code, it effectively asks me to enter the participant's code, but when I try to register this code, it gives me the following error (if 'x' was a participant's code) :
Undefined function or variable 'x'.
Do you have an idea of what could cause this kind of error in this case? It surprises me as it is one of the first lines of my code and as it is not a complex function.
Thanks,
  댓글 수: 1
Jan
Jan 2022년 10월 21일
Please post the complete error message, this means all of the red text. What does this mean: "but when I try to register this code"?
Are you sure that you run this code?

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

채택된 답변

Matt
Matt 2022년 10월 21일
편집: Matt 2022년 10월 21일
The function
codeA = input('Code of the first participant: ', 's');
creates a string variable in your environnement called codeA. So if you type this function and input 'x' as an answer there are no variable x creater : only a variable of name codeA that is a string with codeA = 'x';
% try this :
codeA = input('Code of the first participant: ', 's');
%type x in your keyboard
x
% you will see an error. Now try
codeA = input('Code of the first participant: ', 's');
% type x in your keyboard
codeA
% you should see 'x' printed
  댓글 수: 1
lucie
lucie 2022년 10월 27일
It worked perfectly, thank you !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by