plot using a for loop on same figure

I'm making a Time Interleaved ADC which is basically made up of sub parallel ADC's.
I'm trying to make a code that is generic in that you simply change one parameter to choose how many sub ADC's there are.
What I want to do is plot the quantized output wave of each sub ADC using a for loop (that uses the generic parameter as its terminating value) and plot them all on a single figure.
The data to be plotted is 3 arrays of < 1 x 81 double > or one array of < 3 x 81 double > for the generic code (using 3 sub channels as example).
The code for a 3 channel plot is below:
% Plot of quantized values
i= figure;
set(i,'name','Quantization','numbertitle','off')
plot(t,Qout_1,'ob-',t,Qout_2,'og-',t,Qout_3,'or-','LineWidth',2);
xlabel('time');
ylabel('voltage');
legend('Quantized Sub ADC 1','Quantized Sub ADC 2','Quantized Sub ADC 2');
axis([0 2.5 -2.5 2.5]);
grid on;
set(gcf,'Position',[150 150 500 500])
And the code I've tried for a generic plot using 3 as the generic parameter is here:
for n=1:1:num
i= figure;
set(i,'name','Quantization','numbertitle','off')
if mod(n,2) == 0 %number is even else
plot(t,(Qout(:,n)'),'or-','LineWidth',2);
else
plot(t,(Qout(:,n)'),'ob-','LineWidth',2);
end
xlabel('time');
ylabel('voltage');
legend('Quantized Sub ADC''s' );
axis([0 2.5 -2.5 2.5]);
grid on;
set(gcf,'Position',[150 150 500 500])
hold off;
end
I've tried using the hold command but it doesn't seem to give the required functionality, and instead creates 3 separate figures rather than one figure with all three ADC outputs on it.
Any help would be greatly appreciated :)

1 commentaire

Azzi Abdelmalek
Azzi Abdelmalek le 6 Mar 2013
What is the required result? 3 in the same figure or what?

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 6 Mar 2013
Modifié(e) : Azzi Abdelmalek le 6 Mar 2013

0 votes

If you want 3 in the same figure, use hold on, and remove from the loop i=figure. If you want 3 figures, that's what your code is doing

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by