Undefined function or variable error

option=input('Do you want to continue?(Y/N)','s');
while option == Y
%here comes body of loop
option=input('Do you want to continue?(Y/N)','s');
end
it says undefined function or variable input when I enter Y

 採用された回答

Jan
Jan 2018 年 12 月 3 日
編集済み: Jan 2018 年 12 月 3 日

0 投票

Replace while option == Y by
while strcmpi(option, 'y')
In your code Y is a function call, not the character, because the quotes are missing. Using strcmpi accepts lower and upper case characters and compares the string in total, not elementwise as teh == operator. See:
c = 'yy'
c == 'y' % This compares both characters and replies [true, true]
strcmp(c, 'y') % This is a scalar as wanted

1 件のコメント

Rabbia Sajjad
Rabbia Sajjad 2018 年 12 月 3 日
It worked. Thank you!

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

その他の回答 (1 件)

カテゴリ

タグ

質問済み:

2018 年 12 月 3 日

コメント済み:

2018 年 12 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by