How to fix "Index exceeds the number of array elements (1)"?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
OLav Røthe Kyte
am 15 Jul. 2019
Bearbeitet: Stephane Dauvillier
am 15 Jul. 2019
% 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
0 Kommentare
Akzeptierte Antwort
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
0 Kommentare
Weitere Antworten (1)
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Antennas, Microphones, and Sonar Transducers finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!