Combining multiple plots in 1 graph

clc;
close all;
clear all;
echo on;
a=1;
b=3; %resolution of 3
f=1; %frequency of analog signal
fs=10; %sampling frequency
t=0:1/fs:10; %time axis
x=a*sin(t) + (a/2)*cos(2*t); %sin and cosine wave
subplot(3,1,1);plot(t,x);grid
Nsamples=length(x); %sample number
q_out=zeros(1,Nsamples); %making an array of size=number of samples
%midrise
del=2*a/(2^b); %determining the step size
Ll=-a+del/2;
Lh=a-del/2;
for i=Ll:del:Lh
for j=1:Nsamples %taking the whole sampled vector
if(((i-del/2)<x(j))&&(x(j)<(i+del/2)))
q_out(j)=i;
end
end
end
subplot(3,1,2);plot(t,q_out);grid %plotting wave forms.
Here's my code, how do I plot them on the same graph? I have tried it before but it seems that it does not work.

1 Kommentar

Qatrisyia Zamzuri
Qatrisyia Zamzuri am 23 Mai 2019
How do I plot the original signal and it's two quantized versions in the same graph?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

madhan ravi
madhan ravi am 23 Mai 2019
Bearbeitet: madhan ravi am 23 Mai 2019

0 Stimmen

Read this once again:
Use hold on after the first plot() call and indeed remove subplot()

5 Kommentare

Qatrisyia Zamzuri
Qatrisyia Zamzuri am 23 Mai 2019
How do i combine 8 levels and 16 levels of quantization in 1 graph?
madhan ravi
madhan ravi am 23 Mai 2019
Bearbeitet: madhan ravi am 23 Mai 2019
Show your code what you changed after my answer.
madhan ravi
madhan ravi am 23 Mai 2019
Bearbeitet: madhan ravi am 23 Mai 2019
Note: "OP deleted the comment to which this comment relates"
Combining multiple plots in 1 graph - was your original question
And from nowhere you post the question which was given to you as a homework/test ???
Qatrisyia Zamzuri
Qatrisyia Zamzuri am 23 Mai 2019
Sorry, here's my code
clc;
close all;
clear all;
echo on;
a=1;
b=3; %resolution of 3
f=1; %frequency of analog signal
fs=10; %sampling frequency
t=0:1/fs:10; %time axis
x=a*sin(t) + (a/2)*cos(2*t); %sin and cosine wave
%subplot(3,1,1);plot(t,x);grid
Nsamples=length(x); %sample number
q_out8=zeros(1,Nsamples);
q_out16=zeros(1,Nsamples);%making an array of size=number of samples
%midrise
del=2*a/(2^b); %determining the step size
Ll=-a+del/2;
Lh=a-del/2;
for i=Ll:del:Lh
for j=1:Nsamples %taking the whole sampled vector
if(((i-del/2)<x(j))&&(x(j)<(i+del/2)))
q_out8(j)=i;
q_out16(j)=i;
end
end
end
subplot(3,1,2);plot(t,x,'r',t,q_out8,'k',t,q_out16,'m');grid %plotting wave forms.
clc;
close all;
clear all;
echo on;
a=1;
b=3; %resolution of 3
f=1; %frequency of analog signal
fs=10; %sampling frequency
t=0:1/fs:10; %time axis
x=a*sin(t) + (a/2)*cos(2*t); %sin and cosine wave
plot(t,x);grid
hold on
Nsamples=length(x); %sample number
q_out8=zeros(1,Nsamples);
q_out16=zeros(1,Nsamples);%making an array of size=number of samples
%midrise
del=2*a/(2^b); %determining the step size
Ll=-a+del/2;
Lh=a-del/2;
for i=Ll:del:Lh
for j=1:Nsamples %taking the whole sampled vector
if(((i-del/2)<x(j))&&(x(j)<(i+del/2)))
q_out8(j)=i;
q_out16(j)=i;
end
end
end
plot(t,x,'r',t,q_out8,'k',t,q_out16,'m');grid %plotting wave forms.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 23 Mai 2019

Bearbeitet:

am 23 Mai 2019

Community Treasure Hunt

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

Start Hunting!

Translated by