Complex Numbers in Matrices
61 views (last 30 days)
Show older comments
My program loop generates 60
N(i,1) = [complex #1; complex #2; complex #3; complex #4],
Here, all the complex numbers are different. Each N has two complex numbers with positive imaginary part and two with negative imaginary part.
I need to isolate two complex numbers with positive imaginary part. And store this complex number in
Matrix1= First accepted Complex Number with positive imaginary part
Matrix2= Second accepted Complex Number with positive imaginary part.
Such that both Matrix 1 and 2, should have 60 complex number each obtained from N.
0 Comments
Answers (1)
Walter Roberson
on 29 Nov 2020
format short
%create some data that has the required characteristics
N = complex(rand(4,60), rand(4,60));
for K = 1 : 60; c = randperm(4,2); N(c,K) = conj(N(c,K)); end
%now process
Matrix1 = N(sub2ind(size(N), sum(cumprod(imag(N) < 0))+1, 1:size(N,2)));
Matrix2 = N(sub2ind(size(N), sum(cumprod(imag(N) > 0))+1, 1:size(N,2)));
%and check.
disp(N(:,1:3))
disp(Matrix1(1:3))
disp(Matrix2(1:3))
%the below is not relevant to the code you wanted. I happened to notice a display bug
%so I am using the below as part of a report to Mathworks.
N(:,1:4)
N(:,1:5)
N(1:10)
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!