I want to ask my user to input a shape:
h=input('What shape do you want?:');
if h==square;
disp(h)
But this never works, Matlab shows me the following error message: "'square' requires Signal Processing Toolbox."
Can someone help me find a way to make this work please :)

 채택된 답변

Star Strider
Star Strider 2018년 10월 9일

0 개 추천

You need to add the 's' to the input argument list, and then use strcmp for the comparison.
Try this:
h=input('What shape do you want?:', 's');
if strcmp(h, 'square')
sprintf('SQUARE!')
end

댓글 수: 1

If you can't use contains() like in my answer because your version of MATLAB is too old, then you can make this more robust by using strcmpi() instead of strcmp() and use strtrim() in case the user put any leading or trailing spaces on their response:
h = input('What shape do you want? ', 's');
if strcmpi(strtrim(h), 'square')
fprintf('SQUARE!\n')
end

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

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 10월 9일

0 개 추천

Try using contains():
clc;
userResponse = input('What shape do you want? ', 's')
if contains(userResponse, 'square', 'IgnoreCase', true)
uiwait(helpdlg('You want a square.'));
else
message = sprintf('%s is an unrecognized response.\nTry again.', userResponse);
uiwait(warndlg(message));
end

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

질문:

2018년 10월 9일

댓글:

2018년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by