fmincon - Index Exceeds Matrix Dimensions

1 view (last 30 days)
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
  6 Comments
Ameer Hamza
Ameer Hamza on 30 Mar 2020
Richard, your code reads several other files too. Also, I suggest reading these files once, at the beginning of your code, and then pass the variables to your function. Reading files repeatedly will significantly slow down your code.
Richard
Richard on 30 Mar 2020
Thank you so much for your reply and help Mr Ameer!

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Mar 2020
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.')
  1 Comment
Richard
Richard on 30 Mar 2020
Thank you so much for your quick response and help, Mr Walter.
It works perfectly to show as a 3D graph.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!