フィルターのクリア

Error: Matrix Dimensions must agree while using char

2 ビュー (過去 30 日間)
Abdul Kazi
Abdul Kazi 2017 年 10 月 7 日
コメント済み: Stalin Samuel 2017 年 10 月 7 日
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

採用された回答

Stalin Samuel
Stalin Samuel 2017 年 10 月 7 日
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)
  2 件のコメント
Abdul Kazi
Abdul Kazi 2017 年 10 月 7 日
IT WORKED! Please can you explain me this magic
Stalin Samuel
Stalin Samuel 2017 年 10 月 7 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by