Index exceeds the number of array elements (1)

조회 수: 3 (최근 30일)
Alper Bora Sezgin
Alper Bora Sezgin 2021년 3월 8일
편집: Jan 2021년 3월 8일
Dear all, how can I fix the error on ES row? I would be grateful if you help me
NDOF = 2*NN;
K = zeros(NDOF,NDOF);
for k = 1:NE
i = CON(k,1);
j = CON(k,2);
dx = COORD(j,1)-COORD(i,1);
dy = COORD(j,2)-COORD(i,2);
a = [-dx/L(k) -dy/L(k) dx/L(k) dy/L(k)];
ES = a'.*EA(k)/L(k)*a;
for m = 1:4
for n = 1:4
mi = ID(k,m);
ni = ID(k,n);
K(mi,ni) = K(mi,ni) + ES(m,n);
end
end
end
  댓글 수: 2
Alper Bora Sezgin
Alper Bora Sezgin 2021년 3월 8일
Here is the full script,
COORD = [0 0; 2 0; 4 0; 2 2; 0 2];
CON = [1 2; 2 3; 3 4; 2 4; 4 1; 4 5];
EQ = [7 8; 5 6; 1 2; 3 4; 9 10];
NR = 4;
NE = size(CON,1);
NN = size(COORD,1);
EA = 0.0015*200*(10^9);
Pf = [0 0 0 0 0 0 0]';
Ur = [0 0 0]';
%---CALCULATION---
%SRUCTURAL INFORMATION
NOS = NE+NR-2*NN;
NOK = 2*NN-NR;
%LENGTH OF ELEMENT
L = zeros(NE,1);
for k = 1:NE
i = CON(k,1);
j = CON(k,2);
dx = COORD(j,1) - COORD(i,1);
dy = COORD(j,2) - COORD(i,2);
L(k) = sqrt(dx^2+dy^2);
end
% ID ARRAY
ID = zeros(NE,4)
for k = 1:NE
i = CON(k,1);
j = CON(k,2);
ID(k,1:2) = EQ(i,1:2);
ID(k,3:4) = EQ(j,1:2);
end
% STIFFNESS MATRIX
NDOF = 2*NN;
K = zeros(NDOF,NDOF);
for k = 1:NE
i = CON(k,1);
j = CON(k,2);
dx = COORD(j,1)-COORD(i,1);
dy = COORD(j,2)-COORD(i,2);
a = [-dx/L(k) -dy/L(k) dx/L(k) dy/L(k)];
ES = a'.*EA(k)/L(k)*a;
for m = 1:4
for n = 1:4
mi = ID(k,m);
ni = ID(k,n);
K(mi,ni) = K(mi,ni) + ES(m,n);
end
end
end
K
Jan
Jan 2021년 3월 8일
I've formatted the code of your messages. Please use the code format button, thanks.
It would be useful to post a copy of the error message. It is easier to solve an error, than to guess, what the error is.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 3월 8일
편집: Jan 2021년 3월 8일
With some guessing:
EA is a scalar:
EA = 0.0015*200*(10^9);
Then you cannot access elements of EA > 1:
for k = 1:NE
...
ES = a'.*EA(k)/L(k)*a;
% ^ Fails for k==2
end
I cannot guess, what you want to do instead.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by