How to fix "Index exceeds the number of array elements (1)"?

조회 수: 1 (최근 30일)
OLav Røthe Kyte
OLav Røthe Kyte 2019년 7월 15일
편집: Stephane Dauvillier 2019년 7월 15일
% degree of freedom
dof=6;
% Properties
a=1;
EI=1000;
EA=10^8;
L=[2*a 2*a a];
psi=[-90 0 90];
a1=[0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0];
a2=[1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0; 0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1];
a3=[0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0];
for i=1:length(L)
psi = psi(i);
L = L(i);
To=[cosd(psi) sind(psi) 0; -sind(psi) cosd(psi) 0; 0 0 1];
Tg=[To zeros(3); zeros(3) To];
k_bar=stiffness(dof, EI, EA, L);
k=Tg'*k_bar*Tg;
end
Function
function [k]= stiffness(dof, EI, EA, L)
my=EA/EI*L^2;
if dof == 6
k=EI/L^3*[my 0 0 -my 0 0;...
0 12 -6*L 0 -12 -6*L;...
0 -6*L 4*L^2 0 6*L 2*L^2;...
-my 0 0 my 0 0;...
0 -12 6*L 0 12 6*L;...
0 -6*L 2*L^2 0 6*L 4*L^2];
elseif dof == 4
k=EI/L^3*[12 -6*L -12 -6*L;...
-6*L 4*L^2 6*L 2*L^2;...
-12 6*L 12 6*L;...
-6*L 2*L^2 6*L 4*L^2];
elseif dof == 2
k=EI/L^3*[1 -1;...
-1 1];
end

채택된 답변

Stephane Dauvillier
Stephane Dauvillier 2019년 7월 15일
편집: Stephane Dauvillier 2019년 7월 15일
Hi,
In you code, first you define L as followed:
L=[2*a 2*a a];
Then, you redifine it to:
L = L(i); % where i is 1
After that L is a scalar and not a vector. SO Next time MATLAB reached the line
L = L(i); % this time i = 2
Since L isn't a vector of 3 number but just 2*a it doesn't works.
Don't overwrite L and it will be fine

추가 답변 (1개)

Torsten
Torsten 2019년 7월 15일
for i=1:length(L)
psi0= psi(i);
L0 = L(i);
To=[cosd(psi0) sind(psi0) 0; -sind(psi0) cosd(psi0) 0; 0 0 1];
Tg=[To zeros(3); zeros(3) To];
k_bar=stiffness(dof, EI, EA, L0);
k=Tg'*k_bar*Tg;
end

카테고리

Help CenterFile Exchange에서 Antennas, Microphones, and Sonar Transducers에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by