필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Tina Barsoumian
Tina Barsoumian 2020년 6월 25일
답변: Takumi 2020년 6월 26일
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

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by