How to plot real and imaginary parts as separate stem plots

14 次查看(过去 30 天)
Hi, I'm currently trying to write a code to plot the real and imaginary parts of a complex number seperately, the complex number is 5e^(-0.01t+i0.6πt) from the interval of [-5,0.1,10]. My code to write the two plots seperately, using laws of exponentials is:
figure
X = linspace(-5,0.01,10)';
Y = [5.*exp(-0.01.*x), 5.*exp(i.*0.06.*pi.*x)];
stem(Y)
however, doing so is only producing one graph along with the error message
Warning: Using only the real component of complex data.
> In matlab.graphics.chart.internal.getRealData (line 52)
In stem (line 40)
Could someone explain to me the meaning of the error message, and if this is a correct code to stem plot the real and imaginary parts? Thanks.

回答(1 个)

Arif Hoq
Arif Hoq 2022-2-5
Try this:
figure(1)
x = linspace(-5,0.01,10)';
Y = [5.*exp(-0.01.*x), 5.*exp(i.*0.06.*pi.*x)];
subplot(2,1,1)
stem(real(Y)) % real part
subplot(2,1,2)
stem(imag(Y)) % imaginary part
% if you want the both part
figure(2)
stem(Y)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by