Index in position 3 exceeds array bounds (must not exceed 1).

I'm currently changing a 2D Truss program to 3D and im not sure how to change line 22. The excel file is attatched if needed

15 Comments

Can you include the actual code that produces the error?
But, probably this line:
S=zeros(3*NON,3*NON);
should be
S=zeros(3*NON,3*NON,3*NON);
The code in the picture does not agree with the error message. The one in the picture only uses two indices on that line.
I attached the matlab file and I changed that line but now I get an error code for line 22 saying the matrix dimensions don't agree. I have never really used matlab before, so thank you for the help!
the attached file still doesn't agree with the error message
Also, can you print the sizes of k,K,T,ID and put them here?
ksize=size(k)
Ksize=size(K)
...
I'm confused why as to why this error message doesn't apply to this code? The code pictured above, when run, gives me the following error message. There's other scripts being called out in the code (MainFile3D) but the error message isn't being produced form one of them
Look at the error message and look at line 22 of the code. They don't agree. Either the code you're running isn't what you're sharing, or the error message is different
Oh I see, I started trying to change the script before taking the screenshot. I updated the picture
Ok, now they agree. But, you changed line 22 back. Why?
Because what I had tried changing it to didn't fix the problem, line 22 is from a 2D truss program and I don't know how to change it for a 3D truss program
For now, try what you had. If there's a new error, update it. If it's the matrix dimensions error, look at the variable sizes:
Print the sizes of k,K,T,ID and put them here?
ID=...
ksize=size(k)
Ksize=size(K)
...
S(ID,ID,ID)=...
I updated with the new error, and i'm sorry but i'm not sure what you mean by printing the sizes
Actually, I'll teach you an easier trick. Run this in the command line:
dbstop if error
then, run your code as before. As soon as it reaches that error, it will stop and enter debug mode. Then, run these lines in the command window and copy the output here:
ksize=size(k)
Ksize=size(K)
Tsize=size(T)
IDsize=size(ID)
Ssize=size(S)
In debug mode, you can also mouse over variables in the function to see their values (or sizes, for larger arrays). This is an invaluable tool for cases like this where the issue is that the size of different variables are not compatible with what you're trying to do with them.
Ok this is what came up when I did that
Ok, lots of thoughts:
Most likely, K and S(ID,ID,ID) should be 6x6x6.
So, it seems like ID should be 1x6, so that S(ID,ID,ID) is 6x6x6. This implies that either NID gain a third element, or there is another element in the ID pattern from NID(1) and NID(2). I couldn't immediately tell you which, but
NID=MEMBERS(i,1:3)
is easy to implement. Then you can check the sizes of everything again and see if they make sense (and, whether the code errors)

Sign in to comment.

Answers (1)

Going through the comments it is evident that when calling
S(ID,ID,ID) = S(ID,ID,ID) + K;
The size of S(ID,ID,ID) is 4*4*4 and size of K is 6*6 which doesn't match and thus you will be getting a error as:
Array dimensions must match for binary array op.
You must change your code accordingly making sure that the dimensions match.

Tags

Asked:

on 25 Feb 2020

Answered:

on 28 Feb 2020

Community Treasure Hunt

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

Start Hunting!