How to decide, number or character!

1 回表示 (過去 30 日間)
dmfwlansejr
dmfwlansejr 2022 年 11 月 7 日
回答済み: Steven Lord 2022 年 11 月 7 日
A = ';A0sf1001p00';
A(1) = ';'
A(2) = 'A';
A(3) = '0';
I want to following
for n=1:10
X=str2num(A(n));
if X(1) == Number ? <--Waht is the this Code?
num=X;
else
discard
end
end
Result :
num=0100100

回答 (2 件)

Stephen23
Stephen23 2022 年 11 月 7 日
A = ';A0sf1001p00';
X = isstrprop(A,'digit');
N = A(X)
N = '0100100'

Steven Lord
Steven Lord 2022 年 11 月 7 日
If for whatever reason (homework?) you cannot just use isstrprop like @Stephen23 suggested, look at the documentation page for the str2num function. What is it documented to return if the input is not the text representation of a number? How would you detect that output?

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by