Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 单一矩阵结果';eul';在';对于';环_Matlab_For Loop_Euler Angles - Fatal编程技术网

Matlab 单一矩阵结果';eul';在';对于';环

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”循环,通过随机选择每个循环的角度,生成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);

     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});