Find the indices of the imaginary element of the matrix
34 次查看(过去 30 天)
显示 更早的评论
Suppose I have a Matrix like this:
A=[1 2 3;
4+i 5 6-i;
7 8+i 9]
Now, I want to know if there is a way to find the indecies of the imaginary elements (by this I mean the complex numbers which have imaginary part). I am looking for an answer like that:
A(2,1)
A(2,3)
A(3,2)
or any other form the conveys the indecies information of the imaginary elements.
Thank you so much.
0 个评论
采纳的回答
更多回答(3 个)
Joseph Cheng
2021-6-8
you can do a comparison to the real(A) like
A=[1 2 3;
4+i 5 6-i;
7 8+i 9]
[row col]=find(A~=real(A))
then with find you can get the row and column index values of the as real(A)~=A
Scott MacKenzie
2021-6-8
% test matrix
A=[1 2 3;
4+i 5 6-i;
7 8+i 9]
% identify imaginary elements in A (+1 or -1)
B = imag(A)
% generate column vector of indices of imaginary elements in A
find(B~=0)
Output:
A =
1 + 0i 2 + 0i 3 + 0i
4 + 1i 5 + 0i 6 - 1i
7 + 0i 8 + 1i 9 + 0i
B =
0 0 0
1 0 -1
0 1 0
ans =
2
6
8
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!