フィルターのクリア

How to plot real and imaginary parts as separate stem plots

8 ビュー (過去 30 日間)
Anthony Koning
Anthony Koning 2022 年 2 月 5 日
回答済み: Arif Hoq 2022 年 2 月 5 日
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 Center および File ExchangeStem Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by