how can I divide a vector in imaginary and real part ?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sami
am 24 Jan. 2013
Kommentiert: Dyuman Joshi
am 27 Dez. 2023
hi,
I have a vector X=[-8,-6,-5+8i,-3,-6+6i,-2], and i want to divide it in imaginary and in real part in two vectors like this :
X_real=[-8,-6,-3,-2]
X_imag=[-5+8i,-6+6i]
any idea ? thans :)
0 Kommentare
Akzeptierte Antwort
Wayne King
am 24 Jan. 2013
Bearbeitet: Wayne King
am 24 Jan. 2013
X_real = real(X);
X_imag = imag(X);
It's better style to write the unit imaginary as 1i, so
6+6*1i
However, in your example X_imag does not just contain the imaginary part. If you really want "X_imag" to just select those elements of X with nonzero imaginary part, you can do
idx = find(imag(X) ~= 0);
X_new = X(idx);
Note I have changed the name, because X_imag is not really appropriate for what you get.
10 Kommentare
Weitere Antworten (1)
Hassaan
am 27 Dez. 2023
% Original complex vector
X = [-8, -6, -5+8i, -3, -6+6i, -2];
% Real part of the vector
X_real = real(X);
% Imaginary part of the vector, retaining the 'i' in the output
X_imag = imag(X) * i;
% Display the results
disp('Real part:');
disp(X_real);
disp('Imaginary part:');
disp(X_imag);
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
1 Kommentar
Dyuman Joshi
am 27 Dez. 2023
Your answer does not give as output what OP expects, you might wanna read the question (again).
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!