Matlab如何把cell转换成数值型。
조회 수: 36 (최근 30일)
이전 댓글 표시
如a(1X6的cell)
'1.025000e-06' '1.050000e-06' '1.075000e-06' '1.100000e-06' '1.125000e-06' '1.150000e-06'
댓글 수: 0
채택된 답변
果博东方官网【微8785092】
2023년 5월 17일
楼主的代码有问题,用你的方法不行的。楼主可能是用这种方法生成的cell数组:
>>a={'1.025000e-06' '1.050000e-06' '1.075000e-06' '1.100000e-06' '1.125000e-06' '1.150000e-06'}
a =
'1.025000e-06' '1.050000e-06' '1.075000e-06' '1.100000e-06' '1.125000e-06' '1.150000e-06'
cell中的每个元素是一个含有数字的字符串。所以cell2mat就转换成了char类型的了。
用下面的方法:
a={'1.025000e-06' '1.050000e-06' '1.075000e-06' '1.100000e-06' '1.125000e-06' '1.150000e-06'};
num=length(a);
for ii=1:num
b(ii)=str2double(a{1,ii});
end
b
b =
Columns 1 through 5
1.025e-006 1.05e-006 1.075e-006 1.1e-006 1.125e-006
Column 6
1.15e-006
>>
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!