Matrix dimension problem when asking 'What is your name?'
Show older comments
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
Answers (2)
Azzi Abdelmalek
on 23 Nov 2014
Edited: Azzi Abdelmalek
on 23 Nov 2014
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
on 23 Nov 2014
Use isequal
prompt = 'What is your name?'
N = input(prompt,'s');
if isequal(N,'Jack')
disp('Jack is great!');
else
disp('Hello');
end
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!