Suscripted Assignment in to Mxarray is not supported for code generation

조회 수: 1 (최근 30일)
Joseph
Joseph 2024년 9월 6일
답변: MULI 2024년 9월 10일
Gamma=zeros(n_y*Np,n);
cont=1;
for k=1:n_y:n_y*Np
row_i=k;
row_f=k+n_y-1;
Gamma(row_i:row_f,:)=C*A^(cont);
cont=cont+1;
end
outputs.
Error:Subscripted assignment into an mxArray is not supported for code generation.
Function 'MATLAB Function' (#484.1885.1905), line 85, column 5:
"Gamma(row_i:row_f,:)"
Launch diagnostic report.
  댓글 수: 2
Shivam Gothi
Shivam Gothi 2024년 9월 6일
Hello @Joseph,
Can you please share the complete code so that I can reproduce the error from my end and try to get a possible work around for it?
Walter Roberson
Walter Roberson 2024년 9월 6일
I notice that each iteration of the loop, it sets n_y rows to a value, and the next iteration overwrites all but one of the rows. This feels like a waste of time.

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

채택된 답변

MULI
MULI 2024년 9월 10일
Hi Joseph,
I understand that you are facing an error when trying to convert MATLAB code to C/C++ using MATLAB Coder.
This error is related to dynamic indexing that MATLAB Coder cannot handle due to its requirement for fixed-size arrays due to the following reasons:
Dynamic Indexing: Even though `Gamma` is preallocated with a fixed size, the assignment the line “Gamma(row_i:row_f, :) = C * A^(cont) involves dynamic indexing, which MATLAB Coder cannot handle.
Matrix Operation Compatibility: The result of C * A^con must match the size of the submatrix Gamma(row_i:row_f, :). If the dimensions do not match, it leads to an error.
To resolve this issue, you may follow these steps:
  • Make sure that the matrices `C` and `A` have fixed sizes. For instance, if `C` is `(n_y, m)` and `A` is `(m, m)`, the result `C * A^cont` should be `(n_y, m)`.
  • Ensure that `m` equals `n` so that the result of the multiplication fits into the submatrix of `Gamma`.
By ensuring that all arrays and matrix operations have fixed and compatible sizes, you can avoid the error during code generation.
You can refer to these links where similar query is answered

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by