Error in generating C/C++ codes: Cannot assign a complex value into a non-complex location
13 次查看(过去 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?
0 个评论
回答(1 个)
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 个评论
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.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!