Complex Numbers in Matrices
조회 수: 21 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2020년 11월 29일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!