fmincon - Index Exceeds Matrix Dimensions

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 commentaires

I cannot run your code because it require the file 'truss1.tcl'. But from the error message It appear that in the line
elnodes = elem(iel, 1:3);
you are trying to access elements in the matrix elem which does not exist. You can add breakpoint on this line to check the dimensions of elem matrix.
Richard
Richard le 29 Mar 2020
Mr Ameer thank you for your reply.
Yeah. The code supposedly to be elnodes = elem(iel, 1:2); since the element size is only 25x2. However, exactly the same errors still appeared.
Hope that Mr Ameer can give me some advices.
Walter Roberson
Walter Roberson le 29 Mar 2020
We do not have information about the format of the truss file.
What we can say is that if the z data exists in the truss file at all (not certain) then your code never reads it in.
Richard
Richard le 30 Mar 2020
Dear friends,
A copy of my truss1.tcl is attached in txt format.
Yeah, the code never reads my z data in.
Thanks.
Ameer Hamza
Ameer Hamza le 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 le 30 Mar 2020
Thank you so much for your reply and help Mr Ameer!

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaire

Richard
Richard le 30 Mar 2020
Thank you so much for your quick response and help, Mr Walter.
It works perfectly to show as a 3D graph.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by