フィルターのクリア

Unwanted line on plot

12 ビュー (過去 30 日間)
Steve
Steve 2012 年 2 月 28 日
I am plotting real time data and I have a continually updating plot. I want to show 50 points on the graph and update as more data comes in. Here is currently what I am doing:
while 1
for i=1:50
plot(x,y)
end
end
Now the problem with this is that once the for loop gets back to the first element, on the plot there is a line that connects the left most data point to the right most data point and continues until the program is stopped.
Is there anyway to get around this line?
EDIT: Adding the complete example
count = 0;
while count < 3
for i = 1 : 30
num1 = rand + 1;
Out1(i) = num1;
c=clock;
Time(i)=(c(5)+(c(6)/100));
plot(Time,Out1)
drawnow();
end
count = count + 1;
end
  1 件のコメント
Jan
Jan 2012 年 2 月 28 日
The posted code does not reproduce the problem, because x and y are not defined. Perhaps you simply wand "plot(x,y,'0')", but this is not clear.

サインインしてコメントする。

採用された回答

Jiro Doke
Jiro Doke 2012 年 2 月 29 日
Is this what you're looking for?
count = 0;
Out1 = nan(1, 30);
Time = nan(1, 30);
while count < 3
for i = 1 : 30
num1 = rand + 1;
c=clock;
Out1 = [Out1(2:end), num1];
Time = [Time(2:end), (c(5)+(c(6)/60))];
plot(Time,Out1)
pause(0.1);
end
count = count + 1;
end

その他の回答 (3 件)

Steve
Steve 2012 年 2 月 28 日
Sorry about that. Here is an example of what I am doing:
count = 0;
while count < 3
for i = 1 : 30
num1 = rand + 1;
Out1(i) = num1;
c=clock;
Time(i)=(c(5)+(c(6)/100));
plot(Time,Out1)
drawnow();
end
count = count + 1;
end
A Once the array reloops to the beginning, there is a line connecting the first point to the latest/newest point. I can kind of understand why, but I guess I just don't have a clue how to get around this.

Jiro Doke
Jiro Doke 2012 年 2 月 29 日
[Old Answer]
You're seeing that behavior because you have data points remaining from the previous loop. You can reset the variables Out1 and Time.
count = 0;
while count < 3
Out1 = nan(1, 30);
Time = nan(1, 30);
for i = 1 : 30
num1 = rand + 1;
Out1(i) = num1;
c=clock;
Time(i)=(c(5)+(c(6)/100));
plot(Time,Out1)
drawnow();
end
count = count + 1;
end
BTW, this is called Preallocation which is a good practice when you're assigning values to an array in a loop.

Steve
Steve 2012 年 2 月 29 日
Thanks for the response. However, once 30 points fill the graph, what I want to do is continually update the graph. So when data point 31 comes in I want the first point to go away. So overally once the graph fills with data, I don't want to reset the graph.
  1 件のコメント
Steve
Steve 2012 年 2 月 29 日
This is exaclty what I am looking for. Thank you!!

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-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