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

1 Ansicht (letzte 30 Tage)
% 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

Akzeptierte Antwort

Stephane Dauvillier
Stephane Dauvillier am 15 Jul. 2019
Bearbeitet: Stephane Dauvillier am 15 Jul. 2019
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

Weitere Antworten (1)

Torsten
Torsten am 15 Jul. 2019
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

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by