Freehand drawing in axes

4 ビュー (過去 30 日間)
dan kin
dan kin 2013 年 5 月 12 日
Dear All,
I want to draw multiply lines (freehand) in one axes (e.g., paintAxes) which is one of many axes in a GUI.
I tried the solution provided by Doug Schwarz in http://www.mathworks.in/matlabcentral/newsreader/view_thread/30168#75552
The code is:
function sketch(cmd)
if nargin == 0
cmd = 'init';
end
switch cmd
case 'init'
fig = figure('DoubleBuffer','on','back','off');
info.ax = axes('XLim',[0 1],'YLim',[0 1]);
info.drawing = [];
info.x = [];
info.y = [];
set(fig,'UserData',info,...
'WindowButtonDownFcn',[mfilename,' down'])
case 'down'
myname = mfilename;
fig = gcbf;
info = get(fig,'UserData');
curpos = get(info.ax,'CurrentPoint');
info.x = curpos(1,1);
info.y = curpos(1,2);
info.drawing = line(info.x,info.y,'Color','k');
set(fig,'UserData',info,...
'WindowButtonMotionFcn',[myname,' move'],...
'WindowButtonUpFcn',[myname,' up'])
case 'move'
fig = gcbf;
info = get(fig,'UserData');
curpos = get(info.ax,'CurrentPoint');
info.x = [info.x;curpos(1,1)];
info.y = [info.y;curpos(1,2)];
set(info.drawing,'XData',info.x,'YData',info.y)
set(fig,'UserData',info)
case 'up'
fig = gcbf;
set(fig,'WindowButtonMotionFcn','',...
'WindowButtonUpFcn','')
end
I still have few problems which I would be grateful if you can help:
- when I call it opens a new figure, how can I disable it and how I can make it to allow drawing only in my specific axes?
-How can I change the line thickness?
Thanks a lot in advance.

回答 (1 件)

Image Analyst
Image Analyst 2013 年 5 月 12 日
Try commenting out this line:
fig = figure('DoubleBuffer','on','back','off');
  2 件のコメント
dan kin
dan kin 2013 年 5 月 13 日
I tried the comment option and it does not work. I still get a big axes which overlaps the other axes in the GUI.
It seems that line 13-14 in the sketch is also an error:
set(fig,'UserData',info,...
'WindowButtonDownFcn',[mfilename,' down'])
Any idea how to solve it?
Thanks
Image Analyst
Image Analyst 2013 年 5 月 13 日
編集済み: Image Analyst 2013 年 5 月 13 日
Try this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ to see where the additional figure pops to life.

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by