How to fix "Index exceeds the number of array elements (1)"?
1 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!