请问matlab里面如何区分A是数字还是字符串

2025-01-05 03:58:39
推荐回答(4个)
回答1:

>> x='2';y=2;>> ischar(x)ans = 1>> ischar(y)ans = 0>> isnumeric(x)ans = 0>> isnumeric(y)ans = 1>> class(x)ans =char>> class(y)ans =double>> whos x y Name Size Bytes Class Attributes x 1x1 2 char y 1x1 8 double >> isa(x,'char')ans = 1>> isa(y,'char')ans = 0>> isa(x,'numeric')ans = 0>> isa(y,'numeric')ans = 1>>

回答2:

matlab 获取字符串中的数字。

str='1999.jpg'

A=isstrprop(str,'digit')

B=str(A)

C=str2num(B)

回答3:

x='2';y=2;
ischar(x)
ischar(y)
isnumeric(x);
isnumeric(y);
class(x);
class(y);
ischar(x);
whos x y Name Size Bytes Class Attributes x 1x1 2 char y 1x1 8 double
isa(x,'char');
isa(y,'char');
isa(x,'numeric');
isa(y,'numeric');

回答4:

A是字符类型吧,可以转换为ASCII编码,如果是字符串的话会有单引号的‘A’.大概就是这样。