【发布时间】:2016-12-09 07:44:52
【问题描述】:
我有以下代码:
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. in 不再返回包含字符串的元胞数组,而是包含双精度的元胞数组。
[ 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);
有人能解释一下为什么会这样吗?我认为这会是一种更好的做事方式,但它似乎完全违法......
【问题讨论】:
-
请参阅This doc,了解如何索引元胞数组
标签: matlab cell-array