MATLAB: Any ideas on locating complex numbers in a matrix and changing their value to zero

complex solutionfindsolution constraintsurf

Hello dear Mathworks world. I am having a little problem using the surf function in order to plot an energy surface with respect to two independent compositions (in a ternary system).
The problem seems to lie with the way I generate the solution, called Z. For some combinations of compositions, Z is is complex (which makes sense because they would be impossible in real life). However, the z matrix is quite large and changing these by hand would be intense (I cant even find them to be honest).
I was thinking of using something like: find(GS==nan) = 0; but this did not seem to work. Is there any way to set an elegant constraint on GS to not permit complex numbers in the solution space? I am still pretty new to the world of matlab so any advice is much appreciated.
Thank you! 🙂

Best Answer

  • Z(imag(Z)~=0) = 0;