MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] 怎样把cell中含{‘0089’}转为数值89 (https://www.labfans.com/bbs/showthread.php?t=27351)

guohf00001 2022-09-09 15:56

怎样把cell中含{‘0089’}转为数值89
 
如 a={ '0089' 24.5908 52.9053 15 14; '0089' 24.6311 52.9053 16 14;
'0087' 25.2152 51.1536 15 15;
'0087' 25.2152 51.1536 16 15;
'0087' 25.2152 51.1536 16 15;
'0081' 26.2626 53.9307 16 15 }
想据第一列重复元素分成不同的矩阵,如b=[89 24.5908 52.9053 15 14; 89 24.6311 52.9053 16 14],
c=[87 25.2152 51.1536 15 15; 87 25.2152 51.1536 16 15; 87 25.2152 51.1536 16 15]等。a(:,2:end) 用cell2mat可转为double,但a(:,1) 不能转,用了下面程序:
num=length(a(:,1));
for ii=1:num
B(ii)=str2double(a{ii,1}); % change deviceID (char)to double
end

得到 B=[89 89 87 87 81],但用 ta=tabulate(B)时得到从1到89个数。是不是把a的第一列看成二进制了?要怎样去掉0089前面的两个0,把a分组成b和c形式的矩阵。谢谢


所有时间均为北京时间。现在的时间是 10:54

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.