Error: Matrix Dimensions must agree while using char

1 Ansicht (letzte 30 Tage)
Abdul Kazi
Abdul Kazi am 7 Okt. 2017
Kommentiert: Stalin Samuel am 7 Okt. 2017
a = 10;
b = input('My name is: ', 's');
if b == 'Abdul'
a = 11067;
else
a = 11074;
end
fprintf ('My fav number is : %d ' , a)
Everything works good if I input a name or word with 5 letters, which is the same as 'Abdul' but if I input a word or name containing more letters, Matlab gives me this error:
My name is: fdfdfdffdfdf
Matrix dimensions must agree.
Error in rough (line 7)
if b == 'Abdul'
Please help me how I can be able to make this work regardless of the input char size. I am using MATLAB R2017a. Thank you

Akzeptierte Antwort

Stalin Samuel
Stalin Samuel am 7 Okt. 2017
use "strcmp" for comparison
a = 10;
b = input('My name is: ', 's');
if strcmp(b,'Abdul')
a = 11067;
else
a = 11074;
end
fprintf ('My fav number is : %d ' , a)

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by