我正在学习matlab并尝试使用矢量化来实现small angle approximation。这是我试图实施的公式:
我实现了3个角度:pi / 100
,pi / 10
和pi / 6
。到目前为止,我已经提出了这个问题:
x = [pi / 100, pi / 10, pi / 6];
y = sin(x);
e = (y - x) ./ y;
这很好用。现在,我想将结果解压缩为3个变量。我知道我可以这样做:
RelativeError100 = e(1);
RelativeError10 = e(2);
RelativeError6 = e(end);
但是从蟒蛇背景来看,这对我来说似乎有点笨拙。所以我尝试了这个:
[RelativeError100, RelativeError10, RelativeError6] = e
出错Too many output arguments.
。所以,我做了一些研究,并发现this暗示
[RelativeError100, RelativeError10, RelativeError6] = e{:}
引发Cell contents reference from a non-cell array object.
。
我错过了什么,我怎样才能让它发挥作用?或者用matlab是不可能的?
答案 0 :(得分:3)
怎么样:
x = [pi / 100, pi / 10, pi / 6];
y = sin(x);
e = num2cell((y - x) ./ y);
[RelativeError100, RelativeError10, RelativeError6] = e{:}
因为{:}
仅在e
为cell
而非matrix
时才有效。