# How to eliminate or exclude complix numbers from an array solution?

385 views (last 30 days)
Abdulaziz Abutunis on 14 Feb 2016
Commented: Walter Roberson on 17 Jun 2021
Hello everyone,
Is there any way to eliminate the complex numbers (real and imaginary parts) from a array solution. Or can I exclude the complex elements so the solution will just include the real numbers. For example, in the next array I just want the real elements ( the first four elements. Thanks for any suggestion.
sol =
2.7081096834177947291918098879734
2.4539692532957056897462100829847
1.1392825187840759291489282043638
-4.0494620185638170836265057842329
0.88295725432536163128309307530013 - 0.1308999971886537594046901453934*i
0.1308999971886537594046901453934*i + 0.88295725432536163128309307530013
0.1528510148755374525528985048959*i - 2.0089069727922412635133142708447
- 0.1528510148755374525528985048959*i - 2.0089069727922412635133142708447
##### 2 CommentsShow 1 older commentHide 1 older comment
Walter Roberson on 8 Sep 2020
fs = double(subs(func, {l,m}, {lvalue, mvalue}));
mask = imag(fs) == 0;
[maxvalue, maxidx] = max(fs(mask));
best_l = selected_l(maxidx);
best_m = selected_m(maxidx);

Matt J on 14 Feb 2016
sol = sol(sol==real(sol));
##### 2 CommentsShow 1 older commentHide 1 older comment
Walter Roberson on 14 Feb 2016
The method I would use would be
sol = sol(image(sol)==0);

### More Answers (1)

Jose Perez-Sanabria on 7 Sep 2020
x=x(imag(y)==0);
y=y(imag(y)==0);
##### 2 CommentsShow 1 older commentHide 1 older comment
Walter Roberson on 17 Jun 2021
You fix your objective function so that it never returns complex values, or you set up constraints so that you avoid the area in which it would return complex values. or you use some other kind of multi-objective minimizer that supports complex values.