Undefined function or variable error
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Jan
2018-12-3
编辑:Jan
2018-12-3
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!