I think your error is from here
first you assign zero to nodes with 400 x 8 dimension
nodes = zeros(nel,nnel) ;
later in your reshape you assign dimension 21*21 to NodeNo
NodeNo = reshape(NodeNo,npx,npy);
Then reshape nodes follow below
nodes(:,1) = reshape(NodeNo(1:npx-1,1:npy-1),nel,1);
that's mean now nodes(:,1) has dimesion 441 * 1 then you do similar thing to nodes(:,2), nodes(:,3), nodes(:,4).
Now, Try to think, what is the dimension of nodes(:,5)? originally, you assign zero to nodes(:,5) from 1 to 400, then with new expansion of your nodes, 401 to 441 will be NaN.
At the end
X(:,iel) = coordinates(NaN,1) ;
So how to solve it ? I guess simply to change this line to 21*21 dimension
% your npx is 21 dimension, npy is also 21 dimension
Best Answer