필터 지우기
필터 지우기

Error in generating C/C++ codes: Cannot assign a complex value into a non-complex location

조회 수: 34 (최근 30일)
Codegen is giving the same error for this line:
state.icaweights = V / sqrt(D) * V' * state.icaweights;
When I tried the codegen again by writing:
state.icaweights = complex(V / sqrt(D) * V' * state.icaweights);
OR
state.icaweights = double(V / sqrt(D) * V' * state.icaweights);
it still provided the same error. Can anyone please help in rectification of this error?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 9월 13일
state.icaweights has been created as non-complex, but either V is complex or D is suspected of being negative so code generation figures that the right hand side is generating a complex value.
If you are expecting complex values, then you need to initialize state.icaweights to complex.
For example if you initialized it to 0 before, then initialize it to complex(0,0)
  댓글 수: 6
PIYUSH SWAMI
PIYUSH SWAMI 2021년 9월 17일
편집: Walter Roberson 2021년 9월 18일
Ok, thanks for the explanation :)
Based on your advise, I changed the code to this:
% Orthogonalize weight matrix
[V, D] = eig(state.icaweights * state.icaweights');
% Original V, D
Voriginal = V;
Doriginal = D;
% Real V, D
Vreal = real(V);
Dreal = real(D);
% Thrown V, D
Vthrow = max(abs(imag(Voriginal)));
Dthrow = max(abs(imag(Doriginal)));
state.icaweights = Vreal/sqrt(Dreal)*Vreal' * state.icaweights;
Vthrow and Dthrow returns zero matrix (1 x number of channels). But, when I run the successfully generated MEX file, it is now giving this error:
Error using sqrt (line 13)
Domain error. To compute complex results from real x, use 'sqrt(complex(x))'.
Error in QCAlgo_main>dynamicOrica_modified (line 185)
state.icaweights = Vreal/sqrt(Dreal)*Vreal' * state.icaweights;
Note that the outputs are still non-complex while running the .m file. So when I do as mentioned in the error message, it again shows the original problem as mentioned in the subject :( Can anyone please let me know how to correct this?
Walter Roberson
Walter Roberson 2021년 9월 18일
Compute the whole thing as complex, assigned into a local variable. Extract real() part of that to assign into icaweights .
Simulink appears to be predicting that Dreal is potentially negative. There might be Good Reasons in your case why it cannot be negative for you, but Simulink either does not have sufficient evidence of that or else Simulink just was not able to follow the flow well enough to prove it.

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

카테고리

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