Plotting on the same graph

조회 수: 2 (최근 30일)
SARVESH AGRAWAL
SARVESH AGRAWAL 2017년 10월 5일
댓글: SARVESH AGRAWAL 2017년 10월 6일
Hi, I am trying to plot graphs in a for loop over one another for which, I am using the following code:
for secs=0.75:0.25:1.50
[ etf , decayFct , etfFreq , buildUpNorm , PNR ]=calcEtfSch(data,f_sampl,secs,data_point);
lgSch=10*log10(decayFct);
plT(lgSch,etfFreq);
hold on;
axis([ 0 1.5 -60 0 ]);
xticks([0 .25 0.5 0.75 1.00 1.25 1.50 ])
title( 'Schroeder curves with differing upper integration limits' )
end
However, I get 4 different plots rather than them being on the same graph. I will be glad to get some help.
  댓글 수: 2
KSSV
KSSV 2017년 10월 5일
Where are you plotting?
SARVESH AGRAWAL
SARVESH AGRAWAL 2017년 10월 5일
편집: Walter Roberson 2017년 10월 5일
My bad. The plT function is my plotting function. Following is the code:
function [timLen]=plT(data,sampling_freq)
delta_t=1/sampling_freq;
dataLen=length(data);
timVct=(0:dataLen-1)*delta_t;
timLen=timVct(end);
figure;
plot(timVct,data,'Linewidth',2)
hold on;
end

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 5일
Each figure() call creates a new figure. You should remove the figure() call.
If for some reason it is impossible to remove the figure() call, then it will be necessary to use findobj() to locate all of the plots on all of the figures and merge them into a single plot.
  댓글 수: 1
SARVESH AGRAWAL
SARVESH AGRAWAL 2017년 10월 6일
I got it working right before I saw your answer. Thank you though!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ewout van der Feltz
Ewout van der Feltz 2017년 10월 5일
편집: Ewout van der Feltz 2017년 10월 5일
When plotting recursively it is often practical to use 'hold all' rather than 'hold on'. Include that before plotting the functions and the plots should end up in the same graph.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by