matlab - “for”循环中“eul”函数的单矩阵结果
问题描述
我正在尝试运行一个“for”循环,通过随机选择每个循环的角度,生成 N 个“欧拉角”矩阵,然后将“欧拉角”转换为“旋转角”3x3 矩阵。我的问题是,最后我的结果似乎只有一个欧拉矩阵和一个旋转矩阵,而不是 N 个矩阵。我的代码如下,我的返回怎么可能是 4 个矩阵而不是一个?
`for s = 1 : 4;
Aplha_x(s) = 2 * pi * (rand);
Aplha_y(s) = 2 * pi * (rand);
Aplha_z(s) = 2 * pi * (rand);
eul = [Aplha_z(s) , Aplha_y(s) , Aplha_x(s)];
rotm = eul2rotm (eul);
end `
解决方案
这是因为您在每次迭代时都覆盖了 rotm。
您可以使用元胞数组来存储每次迭代的矩阵,如下所示:
rotm_array = cell(4,1);
for s = 1 : 4
Aplha_x(s) = 2 * pi * (rand);
Aplha_y(s) = 2 * pi * (rand);
Aplha_z(s) = 2 * pi * (rand);
eul = [Aplha_z(s) , Aplha_y(s) , Aplha_x(s)];
rotm = eul2rotm (eul);
rotm_array{s} = rotm;
end
可以使用 rotm_array{s} 打印单个矩阵:
disp(rotm_array{1});
推荐阅读
- c# - 触发/设置数据网格中特定行的样式
- javascript - 水线流回调无法访问
- html - 无法手动将输入范围值设置为零
- python - Python:获取使用运行 Windows 但处理来自 Linux 的文件的脚本创建的日期
- python - spyder IDE 上的无效语法 (pyflakes E)
- node.js - 通过在查询字符串上使用 ${variable} 进行节点和 SQL 注入
- unity3d - 了解 GazeProvider GazeDirection Vector3
- r - parse_stream 似乎没有将我的 json 文件转换为数据框。它给我的结果是空的
- react-native - 世博会和地铁捆绑器:外部模块无法解析反应导入
- php - Laravel:使用 MariaDB 10.6 的 Docker 上的“alter table ...”连接被拒绝