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.
0 个评论
回答(1 个)
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!