Index exceeds the number of array elements (1) Issue

조회 수: 1 (최근 30일)
Sierra Rezell
Sierra Rezell 2020년 12월 4일
댓글: Sierra Rezell 2020년 12월 4일
I keep getting the error "Index exceeds the number of array elements (1)". The error starts at the line with NX1=. I have no idea how to fix this. The goal is to iterate n and m values to find when NX1 is at a minimum
D = zeros(3,3);
D = D + 1/3*Qbar0*(z(2)^3-z(1)^3);
D = D + 1/3*Qbar0*(z(3)^3-z(2)^3);
D = D + 1/3*Qbar90*(z(4)^3-z(3)^3);
D = D + 1/3*Qbar90*(z(5)^3-z(4)^3);
D = D + 1/3*Qbar0*(z(6)^3-z(5)^3);
D = D + 1/3*Qbar0*(z(7)^3-z(6)^3);
R1 = 0;
for n = 1:10
for m = 1:10;
Nx1(n,m) = (pi^2) * ((D(1,1)*(m/a)^2 + 2*(D(1,2) + 2*D(3,3))*(n/b)^2 + D(2,2)*(n/b)^4 * (a/m)^2)/ (1 + R1((a/b * n/m)^2)))
end
end
min(min(Nx1))
  댓글 수: 3
Sierra Rezell
Sierra Rezell 2020년 12월 4일
There's more code above that I didn't paste. It's populating D for each stiffness of a compsite lamina layer then adding them together to give me the overall stiffness of the laminate. There are 6 plies. I get a total 3X3 matrix when I run the code. I'm really just intersted in why I keep getting index errors...unless my D is the problem. But, another homework partner wrote the same code for his D matrix and his works
Sierra Rezell
Sierra Rezell 2020년 12월 4일
D =
52.5819141058867 1.54217882265828 0
1.54217882265828 6.38374676045909 0
0 0 2.99475
This is the matrix I get, and according to the cheat code, this is correct. I want to use the D11,D12,D22,D33 values in the formula and only be changing my m and n from 1-10

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

답변 (1개)

Théophane Dimier
Théophane Dimier 2020년 12월 4일
Have you checked if Nx1 is not already existing before the for loop? It might be that it already exists and that it is a scalar. A hint could be to clear the workspace at the beginning of the code. Anyway, you can trigger "Pause on error" (click on the small arrow under the "Run" button). It will pause the execution right before the error, then launch the code and when it stops, look at the list of variable to check if Nx1 is not just a scalar.
  댓글 수: 1
Sierra Rezell
Sierra Rezell 2020년 12월 4일
Nope, not a scalar. Nx1 can't be calculated because the index exceeds array elements.

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

카테고리

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