-1

i am trying to run a 'for' loop that generates N number of 'Euler angle' matrices, by randomly selecting angles each loop, and then transform the 'Euler angle' to 'rotation angle' 3x3 matrix. my problem is that at the end my outcome seems to be only one Euler matrix and one rotation matrix and not N matrices.My code is as follows, how can my return be 4 matrices and not one?

`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 `
MJac
  • 1
  • 1

1 Answers1

2

This is because you are over-writing the rotm at every iteration.

You can use a cell array to store the matrix for each iteration like this:

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

The individual matrices can be printed by using rotm_array{s} :

disp(rotm_array{1});
s_majee
  • 36
  • 4