文档库 最新最全的文档下载
当前位置:文档库 › 基于matlab的手写输入板

基于matlab的手写输入板

基于matlab的手写输入板
基于matlab的手写输入板

Matlab手写输入板

因为想做个手写数字识别,就先做了这手写输入的面板,这是我根据matlab中文论坛里的一篇文档写的。M文件比较麻烦,删掉了些注释。

下面是GUI和M文件

M文件直接从控件开始吧

% --- Executes on mouse press over figure background, over a disabled or

% --- inactive control, or over an axes background.

function figure1_WindowButtonDownFcn(hObject, eventdata, handles)

global draw_enable %定义一个标志,1表示绘图,0表示停止绘图

global x;

global y;

global h1;

draw_enable=1;

if draw_enable==1

p=get(gca,'currentpoint'); %鼠标按下,获取当前坐标

x(1)=p(1);

y(1)=p(3);

% --- Executes on mouse motion over figure - except title and menu. function figure1_WindowButtonMotionFcn(hObject, eventdata, handles) global draw_enable;

global x;

global y;

global h1;

p=get(gca,'currentpoint');

if draw_enable==1

x(2)=p(1); %鼠标第一次移动后的坐标为x(2),y(2)

y(2)=p(3);

h1=line(x,y,'EraseMode','xor','LineWidth',5,'color','b');

x(1)=x(2);

y(1)=y(2); %鼠标移动时,随时更新折线的数据

end

% --- Executes on mouse press over figure background, over a disabled or % --- inactive control, or over an axes background.

function figure1_WindowButtonUpFcn(hObject, eventdata, handles) global draw_enable;

draw_enable=0;

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

axes(handles.axes1);

cla; %清空,但cla是清楚坐标抽,故在下面又建立一个坐标轴,且取tag名为axes1 axes('Position',[19.8 12.923 70.2 15.462],'tag','axes1');

效果图

相关文档