"Conversion to double from cell is not possible." 但输入是双精度元胞数组

"Conversion to double from cell is not possible." but input is cell array of doubles

我有以下代码:

Xh = zeros(InfDS.statedim,N);                          
Xh(:,1) = str2double(states_0(2:end,2));
Px = diag(str2double(states_0(2:end,3)));

其中 states_0 是一个 Nx3 元胞数组。例如,它可能如下所示:

''       'x0'       'P0'  
'SOC'    '100'      '0.75'
'RI'     '0.001'    '0.75'

但它还可以包含更多参数。

我的问题是我重写了部分代码,s.t。不再是 return 包含字符串的元胞数组,而是包含双精度数的元胞数组。

[       100]    [0.7500]
[1.0000e-03]    [0.7500]

我认为由于转换次数较少,这会更容易使用,但似乎并非如此……我已经尝试过:

Xh = zeros(InfDS.statedim,N);
Xh(:,1) = states_0(1:end,1);
Px = diag(states_0(1:end,2));

但这给了我错误:

Conversion to double from cell is not possible.

Error in testfile (line 61)
Xh(:,1) = states_0(1:end,1);

有人可以解释为什么会这样吗?我认为这是一种更好的做事方式,但它似乎完全违法......

cell2mat() 似乎可以解决问题!

注意:我猜string2double隐式转换为数组?