Help with "Index exceeds matrix dimensions" please

Hi, This is the Part of the code I am stuck with-
clc
clear all
E=70e9; %%Youngs modulus (Pa)
A=0.001; %%Area (m)
ks=3e6; %%spring stiffness (Nm)
P=10e3; %%pulling force (N)
nC=[0 0;0 3; 0 7;4 3]; %%Nodal coordinate data
nEl=4; %%No of Elements
nDOF=size(nC,1)*2; %%Number of degrees of freedom
ElConn=[1 4;2 4;3 4;4 5] %%Element Conectivity
%% Formulate Element Stiffness matrices
k= zeros(4,4,nEl);
for count=1:nEl;
n1=ElConn(count,1);
n2=ElConn(count,2);
x1=nC(n1,1)
x2=nC(n2,1)
y1=nC(n1,2);
y2=nC(n2,2);
le=sqrt((x2-x1).^2+(y2-y1).^2);
kdash=((E*A)/le)*[1 -1;-1 1];
l=(x2-x1)/le;
m=(y2-y1)/le;
L=[l m 0 0;0 0 l m];
k(:,:,count)=L'*kdash*L;
end
The Error I am Getting is in line 22 "x2=nC(n2,1)" I think the values I should be getting for x2 are 0, 3, 7 and 3
Thanks in advance for any help

Antworten (1)

Swarooph
Swarooph am 18 Okt. 2016
Bearbeitet: Swarooph am 18 Okt. 2016

0 Stimmen

It seems like during the 4th iteration, n2 is being set to 5 and then x2 is being assigned a value of nC(5,1). However nC is of size 4x2. Hence the error.
Use the MATLAB debugger to help with these types of issues. This documentation will help.
Specifically you can also enter debug mode when encountering errors using the dbstop if error option. Check the documentation here.

Kategorien

Produkte

Gefragt:

am 18 Okt. 2016

Bearbeitet:

am 18 Okt. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by