フィルターのクリア

ask: how do I insert an image (background) on the axes and draw on it (background)? here the code:

1 回表示 (過去 30 日間)
Hendri Setiawan
Hendri Setiawan 2013 年 12 月 16 日
編集済み: DGM 2023 年 3 月 30 日
function userDraw(handles)
%F=figure;
%setptr(F,'eraser'); %a custom cursor just for fun
A=axes;
% axesUserDraw is tag of my axes
set(A,'buttondownfcn',@start_pencil)
function start_pencil(src,eventdata)
coords=get(src,'currentpoint');
%since this is the axes callback, src=gca
x=coords(1,1,1);
y=coords(1,2,1);
r=line(x, y, 'color', [0 .5 1], 'LineWidth', 2, 'hittest', 'off');
%turning hittset off allows you to draw new lines that start on top of an existing line.
set(gcf,'windowbuttonmotionfcn',{@continue_pencil,r})
set(gcf,'windowbuttonupfcn',@done_pencil)
function continue_pencil(src,eventdata,r)
%Note: src is now the figure handle, not the axes, so we need to use gca.
coords=get(gca,'currentpoint'); %this updates every time i move the mouse
x=coords(1,1,1);
y=coords(1,2,1);
%get the line's existing coordinates and append the new ones.
lastx=get(r,'xdata');
lasty=get(r,'ydata');
newx=[lastx x];
newy=[lasty y];
set(r,'xdata',newx,'ydata',newy);
function done_pencil(src,evendata)
%all this funciton does is turn the motion function off
set(gcf,'windowbuttonmotionfcn','')
set(gcf,'windowbuttonupfcn','')

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by