Matlab 单一矩阵结果';eul';在';对于';环
我尝试运行一个“for”循环,通过随机选择每个循环的角度,生成N个“Euler angle”矩阵,然后将“Euler angle”转换为“rotation angle”3x3矩阵。我的问题是,最后我的结果似乎只有一个Euler矩阵和一个旋转矩阵,而不是N个矩阵。我的代码如下,我的返回怎么可能是4个矩阵而不是一个Matlab 单一矩阵结果';eul';在';对于';环,matlab,for-loop,euler-angles,Matlab,For Loop,Euler Angles,我尝试运行一个“for”循环,通过随机选择每个循环的角度,生成N个“Euler angle”矩阵,然后将“Euler angle”转换为“rotation angle”3x3矩阵。我的问题是,最后我的结果似乎只有一个Euler矩阵和一个旋转矩阵,而不是N个矩阵。我的代码如下,我的返回怎么可能是4个矩阵而不是一个 `for s = 1 : 4; Aplha_x(s) = 2 * pi * (rand); Aplha_y(s) = 2 * pi * (rand);
`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_数组{s}打印各个矩阵:
disp(rotm_array{1});