Matlab如何把cell转换成数值型。

36 views (last 30 days)
如a(1X6的cell)
'1.025000e-06' '1.050000e-06' '1.075000e-06' '1.100000e-06' '1.125000e-06' '1.150000e-06'

Accepted Answer

果博东方官网【微8785092】
楼主的代码有问题,用你的方法不行的。楼主可能是用这种方法生成的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
>>

More Answers (0)

Categories

Find more on 编程 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!