필터 지우기
필터 지우기

Attempt to extract field 'iterations' from 'mxArray'

조회 수: 6 (최근 30일)
Grek Vardugin
Grek Vardugin 2018년 10월 26일
답변: Grek Vardugin 2018년 11월 11일
Hello! I need help. My problem is in Title. I use codegen for translate .m-code in mex.
[xopt,zmin,exitflag,output,lambda] = linprog(C1,A,B,[],[],LB1,[],[],options);
fprintf(1,Out1,xopt,zmin);
fprintf(1,'ExitFlag= %d\nIterats= %d\n',exitflag,output.iterations);
How can I solve this problem?

채택된 답변

Grek Vardugin
Grek Vardugin 2018년 11월 11일
I solve it. First, I created a new structure with fields that exist in the output structure.
output = struct('iterations', 0, 'constrviolation', 0, 'message', '', 'algorithm', '', 'firstorderopt', 0);
Then I added the coder.varsize function for text fields.
coder.varsize('output.message', [1,100]);
coder.varsize('output.algorithm', [1,100]);
After
[xopt,zmin,exitflag,output,lambda] = linprog(C,A,B,Aeq,Beq,lb,ub,[],options);
fprintf(1,Out1,xopt,zmin);
fprintf(1,'\nExitFlag = %d\nIterats = %d\n',exitflag,num2str(output.iterations));

추가 답변 (1개)

Joh Hag
Joh Hag 2018년 10월 26일
hi, is output a struct? the mxArray is just the bare data and does not have such a field. have you tried to put the value in a separate variable such num_iterations = output.iterations? and then use this one in the fprintf command. this could help codegen to sort things out.
  댓글 수: 3
Joh Hag
Joh Hag 2018년 10월 26일
Did you try the trick with the temporary variable? where does the compilation actually fail? at the fprintf's or when you call linprog?
Grek Vardugin
Grek Vardugin 2018년 10월 26일
Compilation failed then I use fprintf. If I use the disp function instead of fprintf, I get a similar error.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by