Codegen saying variable is constrained to being non-complex when it's defined as complex
Show older comments
Any idea why I'd get this error:
The left-hand side has been constrained to be non-complex, but the right-hand side is complex. To correct this problem, make the right-hand side real using the function REAL, or change the initial assignment to the left-hand side variable to be a complex value using the COMPLEX function
When setting up my fields in coder I specifically put the variable as a complex variable. Do I need to explicitly put that in my code as complex? If so, how do I do that? Here is my line of code tripping the error:
yvec1(:,tic_ct) = DelayProfile .* (Fade1.Ix + 1i * Fade1.Qx);
Any ideas?
10 Comments
Walter Roberson
on 23 May 2012
How did you initialize yvec1 ?
yvec1 = complex(zeros(M,N), zeros(M,N));
Kaustubha Govind
on 23 May 2012
+1 for Walter's comment!
Adam Kaas
on 24 May 2012
Walter Roberson
on 24 May 2012
Which line of your MATLAB code is generating that new error?
Adam Kaas
on 24 May 2012
Rick Rosson
on 24 May 2012
It would be helpful to see more of the code, and also the build process you are using. Are you using the GUI to build, command line, or a build script?
Walter Roberson
on 24 May 2012
Are you no longer making the complex assignment to yvec1, and thus have dropped initializing yvec1 as complex() ? Or are you assigning zeros() to yvec1 after it has already been initialized to complex ?
Adam Kaas
on 24 May 2012
Walter Roberson
on 24 May 2012
Why assign the non-complex zeros to a variable that is already complex zeros, especially since you need the variable to store complex values? It seems redundant at best and wrong at worst.
Also, this code gives the impression that out1 is unused ? If it will be a copy of yvec1 after the calculation and if yvec1 is still going to be complex, then out1 should also be initialized as complex.
Adam Kaas
on 24 May 2012
Accepted Answer
More Answers (1)
Prateek Tiwari
on 1 Jun 2020
Hi erveryone, I need to post this question here, because no one responds to the question i have asked in the past. Sorry for that, but would appreciate if you can answer.
Hello everyone, I am having an issue with the interaction of matlab function block in the simulink with my model block. Below you can also find the picture.
I have created a matlab function with three inputs and 1 output. Since in the matlab function block, i have solved an differential equation, it has complex expressions in the form of for example .
(exp(sqrt(-a/b)))
This generates the output of complex data type from the function block. When passing this to the integrator which is the input to my plant, I cannnot run the simulink due to the error
"Cannot pass the complex value to non-complex location"
I tried chaning the data types of integrator, then the same thing happens to other blocks in the simulink.
I also tried using absolute values, which ofcourse gives real number, but turns out to be very large numbr and genrates high magnitude. I really need help in solving this issue.
Can anyone help me in this/
Thanks in advance.

Categories
Find more on Function Definition in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!