Error in generating C/C++ codes: Cannot assign a complex value into a non-complex location
13 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Walter Roberson
on 13 Sep 2021
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 Comments
Walter Roberson
on 18 Sep 2021
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!