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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by