How to check if the input it´s a string?

4 ビュー (過去 30 日間)
Madalena Francisco
Madalena Francisco 2023 年 1 月 15 日
編集済み: Madalena Francisco 2023 年 1 月 15 日
Hi, i´m trying to understand why when the user inputs for example: b, or fbr3f, or any other types of string, it´s giving me error message on Matlab, when I´m using the isstring function and isnumeric too, i´m using the isnumeric in case the user inputs whatever it´s not numeric~, and don´t know if its necessary since I´m using the isstring.
Please help me! Thanks a lot
The isempty works just fine!
clc, clear, close
b1= input('Press number 1 or 2: ');
while (isempty(b1) || isstring(b1) || ~isnumeric(b1))
disp ('Error')
b1= input('Press number 1 or 2');
end
%when the user writes any string appears:
% Error using input
%Unrecognized function or variable ....
%and i really don´t understand why...

採用された回答

MJFcoNaN
MJFcoNaN 2023 年 1 月 15 日
編集済み: MJFcoNaN 2023 年 1 月 15 日
Hello,
you may need the 's' option to avoid evaluating text:
b1= input('Press number 1 or 2: ','s');
  1 件のコメント
Madalena Francisco
Madalena Francisco 2023 年 1 月 15 日
編集済み: Madalena Francisco 2023 年 1 月 15 日
Ohhhh thank uu!! It works!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by