# How to plot real and imaginary parts as separate stem plots

7 views (last 30 days)
Anthony Koning on 5 Feb 2022
Answered: Arif Hoq on 5 Feb 2022
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.

Arif Hoq on 5 Feb 2022
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)

### Categories

Find more on Stem Plots in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!