필터 지우기
필터 지우기

Set up graph before going into for loop, then refresh data in plot after each iteration

조회 수: 19 (최근 30일)
In this program, I wanted to know if it is possible to update just the data points during the for loop, but keep the graph setup the same throughout the for loop process. I tried setting up the graph at first, like the axis, labels and legend ( I had a problem with the legend), then go into the for loop and just refresh the data. In the program below, after each iteration, the old data remains and the graph just keep adding the new data points without getting rid of the old ones. I tried clf, but that command clears the whole graph and I would have to start back from the beginning to set back up the graph.
Is it possible to just refresh the data points after each iteration, or do I have to draw the graph over each time?
Here is the code that I have so far:
N = 10;
h2 = [];
h3 = [];
%%Plot of Original and OMP Signals
figure(1); clf;
axis([1 N -3 3]);
h=xlabel('index [1 to m]');
legend([h2,h3],{'x-Original','x-OMP'})
set(h,'FontSize',14);
ylabel('Amplitude');
set(h,'FontSize',14);
set(gca,'FontSize',14);
Iter = 5;
for ii = 1:1:Iter
if ii == 1 % This is done so as to plot the legend only on the first iteration
A = rand(1,N);
C = rand(1,N);
B = 1:1:N;
pause(1);
%h1 = plot(A);
hold on;
h2 = plot(B,A,'.r');
set(h2,'MarkerSize',15);
h3 = plot(B,C,'.b');
set(h3,'MarkerSize',7);
legend([h2,h3],{'x-Original','x-OMP'});
else
A = rand(1,10);
B = 1:1:N;
C = rand(1,N);
pause(1);
%h1 = plot(A);
hold on;
h2 = plot(B,A,'.r');
set(h2,'MarkerSize',15);
h3 = plot(B,C,'.b');
set(h3,'MarkerSize',7);
end
end

답변 (1개)

Kuifeng
Kuifeng 2016년 4월 3일
편집: Kuifeng 2016년 4월 3일
turn off the 'hold'
"...
%hold on;
...
%hold on;
..."

카테고리

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