MATLAB: Calculate 3 x 3 rotation matrices from 3 x n matrix

3x3 rotation matrixcolumn vectorsfor loophomogeneous coordinatesMATLAB

I am using the following code to open a .csv file, index columns of interest (euler rotations around x, y, z axes) as single column arrays, and then sequentially order these as a 3 x n matrix:
%Imports geometric camera parameters from phtosynth output .csv in the
%current directory and orders columns as seperate 1 x n matrices
if exist('PARAMETERS_0.csv', 'file') == 2
disp('file found')
[PX PY PZ RX RY RZ] = csvimport('PARAMETERS_0.csv', 'columns', {' PositionX', ' PositionY', ' PositionY', ' RotationX', ' RotationY', ' RotationZ'});
else
disp('camera parameters input file not found')
end
% Sequentially indexes RX RY RZ into a 3 x n matrix where columns are euler
% angles around x y z axes
for i=1:length(RX)
MRV(:,i)=[RX(i);RY(i);RZ(i)];
end
The resulting 3 x n matrix looks like this:
[0.5053 0.5300 0.3820 -0.1594 -0.1289 -0.1107 -1.1684
1.4532 1.4258 1.1240 1.2185 1.2424 1.2131 0.9390
1.4532 1.4258 1.1240 1.2185 1.2424 1.2131 0.9390]
Where individual columns represent euler rotations around x, y z axis (in descending order), describing the orientation of a camera:
e.g.
POV1 =
0.5053
1.4532
1.4532
My problem is that I need to use the euler rotations represented as column vectors in the matrix (MRV) as inputs to calculate a 3 x 3 rotation matrix for each camera position (POV1,..,POVn). The functions to achieve this in the command console would be as follows (example using column 1):
Rx1 = [1 0 0; 0 cosd(MPV(1,1)) -sind(MPV(1,1)); 0 sind(MPV(1,1)) cosd(MPV(1,1))];
Ry1 = [cosd(MPV(2,1)) 0 sind(MPV(2,1)); 0 1 0; -sind(MPV(2,1)) 0 cosd(MPV(2,1))];
Rz1 = [cosd(MPV(3,1)) -sind(MPV(3,1)) 0; sind(MPV(3,1)) cosd(MPV(3,1)) 0; 0 0 1];
RM1 = Rz1*Ry1*Rx1
This function would need to be applied sequentially to each column to give an output rotation matrix of the form:
r11 r12 r13
r21 r22 r23
r31 r32 r33
I know that the code needed would be a for loop of some description but am a bit stuck on the nature of the syntax needed. Any help would be greatly appreciated. Note that I need also to concatenate this rotation matrix with a column vector from an equivalent 3 x n matrix to MRV (x y z position) and a single row array (0 0 0 1) to produce a 4 x 4 matrix (homogeneous coordinates) of the form:
r11 r12 r13 x
r21 r22 r23 y
r31 r32 r33 z
0 0 0 1
So any solution would have to be compatible with next stage in the analysis

Best Answer

Ok I found an other way, more properly, to store you resulting matrices. You will store them inside a structure and create dynamics fieldnames.
the final code will looks like this :
euler=struct();
for k=1:size(MPV,2)
Rxk = [1 0 0; 0 cosd(MPV(1,k)) -sind(MPV(1,k)); 0 sind(MPV(1,k)) cosd(MPV(1,k))];
Ryk = [cosd(MPV(2,k)) 0 sind(MPV(2,k)); 0 1 0; -sind(MPV(2,k)) 0 cosd(MPV(2,k))];
Rzk = [cosd(MPV(3,k)) -sind(MPV(3,k)) 0; sind(MPV(3,k)) cosd(MPV(3,k)) 0; 0 0 1];
RMk = Rzk*Ryk*Rxk;
euler.(['PV' num2str(k)])=RMk;
end
then to acces one specific matrix, you have to enter euler.PVi. For example, if you want to access PV1, type euler.PV1