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

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 ?

 채택된 답변

the cyclist
the cyclist 2019년 5월 10일
편집: the cyclist 2019년 5월 10일
% 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

great
Thank you.
But if I want to show me the complex numbers, what should I do ?
for example got them and put in a matrix?
realElements = z(mask);
imagElements = z(~mask);
Hello,
How can i send a three-dimensional matrix to the Excel?
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2019년 5월 10일

댓글:

2019년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by