Matrix dimension problem when asking 'What is your name?'

Here is my matlab code. It only works when the input name is 4 characters long otherwise it gives me matrix dimension error. How to make this work for names of all length
prompt = 'What is your name?'
N = input(prompt,'s');
if N=='Jack'
disp('Jack is great!');
else
disp('Hello');
end

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 23일
편집: Azzi Abdelmalek 2014년 11월 23일
Use isequal instead of ==
prompt = 'What is your name?'
N = input(prompt,'s');
if isequal(N,'Jack')
disp('Jack is great!');
else
disp('Hello');
end
Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 23일
Use isequal
prompt = 'What is your name?'
N = input(prompt,'s');
if isequal(N,'Jack')
disp('Jack is great!');
else
disp('Hello');
end

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

질문:

2014년 11월 23일

편집:

2014년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by