MATLAB Answers

How can I separate complex numbers from the other in a matrix?

32 views (last 30 days)
masoud jiryaei on 10 May 2019
Commented: the cyclist on 18 Jun 2019
Hello
I have a matrix that includes: complex numbers , natural numbers and ...
I want to separate the complex numbers from the other
How can I do this ?
Is there any order in MATLAB ?
0 CommentsShowHide -1 older comments

Sign in to comment.

Accepted Answer

the cyclist on 10 May 2019
Edited: the cyclist on 10 May 2019
% Example data
z = [1 1+2*i 3 4+5*i]
mask = imag(z)==0;
The variable mask is a logical variable that is TRUE at the locations of the numbers that do not have an imaginary component, and FALSE otherwise.
You'll need to be careful if you have imaginary parts that are within floating-point precision of zero. You might need to use a tolerance, rather than strict equality.
6 CommentsShowHide 5 older comments
the cyclist on 18 Jun 2019
Rather than ask in three different places (two questions, and this comment) within one hour, I suggest you be a little patient and see what answers you get on one question. You already have some suggestions in your questions here and here.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!