Turning a Character input into a integer.

조회 수: 12 (최근 30일)
Tom
Tom 2013년 2월 26일
okay so, first of all thanks for helping, second of all im very new to matlab so please bare with me if my terminology is incorrect/my coding is incorrect.
so...
what i want to achieve is for the user to input a character when prompted, and from that stage turn it into a integer, here's what i have so far, i thought this would work ive had a play with other alternatives but really have hit a loose end so have come here to seek advice? thank you in advance for any feedback you guys give! its much appreciated. Heres's what i have made so far..
disp('Text will go here...??:')
input('Type here...','s')
UserIn = ans;
if UserIn == A;
A = str2num('1')
elseif UserIn == B;
B = str2num('2')
else
end
Just to add, the error i get it..
Undefined function or variable 'A'.
Error in CharToBin (line 38) if UserIn == A;

채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 26일
if UserIn == 'A'
However, the user might have entered multiple characters, so you should use strcmp()
if strcmp(UserIn, 'A')
  댓글 수: 1
Tom
Tom 2013년 2월 26일
Thank you for a very quick response and yes i was wondering how i could go about solving that, many thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by