Index in position 1 exceeds array bounds (must not exceed 1). in arrays

2 visualizaciones (últimos 30 días)
Tina Barsoumian
Tina Barsoumian el 25 de Jun. de 2020
Respondida: Takumi el 26 de Jun. de 2020
I am trying to add to a cell in an array I created through a for loop but every time it gets to the second itteration, I get an error - Index in position 1 exceeds array bounds (must not exceed 1). My code is below
function [sW] = skewW(w)
%This function creates a skew symmetirc matrix omega(w)
% This function takes in a 3x1 vector omega and creates a 3x3 skew
% symmetric matrix (sW)
sW=[0 -w(1,1) w(1,2);
w(1,3) 0 -w(1,3);
-w(1,2) w(1,1) 0];
end
% variables
L=0;
theta=[0 0 0 0 pi 0];
% determining w and v
ws1= [0 1 0];
ws2= [0 0 1];
ws3= [0 0 0];
ws4= [0 1 0];
ws5= [0 sin(45) cos(45)];
ws6= [1 0 0];
vs1= [0; 0; 0];
vs2= [-L; 0; 0];
vs3= [0; 1; 0];
vs4= [-L; 0; -2*L];
vs5= [-L*cos(45)-L; L*sin(45); -2*L];
vs6= [0; L; 0];
% Calculating e^[S]theta
I=eye(3);
wS=[ws1; ws2; ws3; ws4; ws5; ws6];
vS= [vs1 vs2 vs3 vs4 vs5 vs6];
R=cell(6,1);
V=cell(6,1);
for i=1:6
R{i}=I+(sin(theta(i,1))*(skewW(wS(i,:))))+((1-(cos(theta(i,1))))*((skewW(wS(i,:)))^2));
V{i}=((I*theta(i,1))+(1-cos(theta(i,1)))*skewW(wS(i,:))+(theta(i,1)-sin(theta(i,1)))*((skewW(wS(i,:)))^2))*vS(:,i);
end

Respuestas (1)

Takumi
Takumi el 26 de Jun. de 2020
Matrix size of “theta” is 1 by 6. So you have to replace theta(i,1) with theta(1,i).

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by