How to error check a string for numbers?
7 次查看(过去 30 天)
显示 更早的评论
So I have an input
name = input('Please enter your name:\n', 's');
How can I error check so that a user cannot enter any numbers for it?
回答(1 个)
KSSV
2018-10-15
name = input('Please enter your name:\n', 's');
if isnan(str2double(name))
fprintf('Input is a string\n')
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!