MATLAB: Fmincon – Index Exceeds Matrix Dimensions

fmincon function

Dear friends,
I am trying to plot a 3D truss structure together with "fmincon" function. I have got an error and couldn't find the problem.
However, the following errors are obtained :
Index exceeds matrix dimensions.
Error in Topo_3D/truss (line 164)
elnodes = elem(iel, 1:3);
Error in Topo_3D/outfun (line 144)
truss(x);
Error in callAllOptimOutputFcns (line 13)
stop(i) = feval(OutputFcn{i},xOutputfcn,optimValues,state,varargin{:});
Error in barrier
Error in fmincon (line 798)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Topo_3D (line 30)
[x,fval,ef,output,lambda,hessian] = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon,options);
A copy of my fmincon function is attached.
I appreciate if somebody can help with this errors and how can it be solved.
Thank you very much!
RTFQ

Best Answer

stread = textscan(st, '%s %f %d %d'); % textscan is reading formatted data from text file or string

nd = [nd; stread{3}, stread{4}];
Change that to
stread = textscan(st, '%s %f %f %f %f'); % textscan is reading formatted data from text file or string
nd = [nd; stread{3}, stread{4}, strread{5}];
After that you should be able to
plot3(node(:,1), node(:,2),node(:,3),'k.')