question about pause function,and real time drawing

3 ビュー (過去 30 日間)
alex
alex 2014 年 10 月 27 日
コメント済み: Geoff Hayes 2014 年 10 月 30 日
Hello!
I use a drawing tablet and i manage to get and save x,y coordinates.
if i want to see what i draw, i use the command
line(x, y, 'Color','k','LineWidth', 1);
If i want to see in real time what i am drawing i use
line(x, y, 'Color','k','LineWidth', 1);
pause(0.001);hold on
The problem is when i use pause, i miss some packets from the tablet,so the drawing is kind of squared and it is different from the non real time drawing.
Any idea what to do at the real time drawing?
Thank you very much!

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 10 月 28 日
Alex - what you are working on sounds cool.
When you call
line(x, y, 'Color','k','LineWidth', 1);
for the real time drawing, do x and y contain all coordinates or only the most recent ones that were sent from the tablet? If the former, then you could try updating the line object instead of creating a new one with each call to line. Presumably you have created a figure (or are drawing on an axes within a GUI), so you could initialize your line as
hLine = line(NaN,NaN, 'Color','k','LineWidth', 1);
Now, when you receive new coordinates, you could just update the current line as
x = [x ; newX];
y = [y ; newY];
set(hLine,'XData',x,'YData',y);
Then, remove the pause and hold statements and replace both with just the drawnow as
x = [x ; newX];
y = [y ; newY];
set(hLine,'XData',x,'YData',y);
drawnow;
The above might speed things up a bit so that you are less likely to miss packets. Try it and see!
  7 件のコメント
alex
alex 2014 年 10 月 30 日
just perfect! everything works fine! thank you very much Geoff!
p.s: the while loop continues to run normally (without the if ~isempty(x) )for 10 seconds without the pen touching the tablet.there was no problem!
Thank you very much again!
Geoff Hayes
Geoff Hayes 2014 年 10 月 30 日
Glad that it is working well, Alex!

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

その他の回答 (1 件)

Mike Garrity
Mike Garrity 2014 年 10 月 28 日
There are a couple of suggestions you might try in this section of the doc .

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by