How to plot real and imaginary parts as separate stem plots

조회 수: 10 (최근 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 CenterFile Exchange에서 Stem Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by