Matlab屏幕交互取点并作三次样条曲线

 

matlab GUI:屏幕取点+三次样条曲线+屏幕拖动

  1010人阅读  评论(0)  收藏  举报
1.  点击GUIDE图标,创建Blanck GUI(default)项目。
    在GUIDE编辑器中添加Axes组件,双击设置其‘Color’属性为黑色,‘NextPlot’属性为‘Add’。
    在相应.m文件中function gui_OpeningFcn(hObject, eventdata, handles, varargin)中添加:
axis([0 1 0 1]);
pdatax=[];  % 屏幕取点功能
pdatay=[];
n=0;
but=1;
while but==1
    [xi,yi,but]=ginput(1);
    n=n+1;
    pmouse_plot(n,1)=plot(xi,yi,'yo');
    pdatax(n,1)=xi;
    pdatay(n,1)=yi;
end

t=1:n;     % 三次样条曲线生成
ts=1:0.1:n;
ppx=spline(t,pdatax(:,1));
ppy=spline(t,pdatay(:,1));
xs=ppval(ppx,ts);
ys=ppval(ppy,ts);
plot(xs,ys,'w-');

2. 添加function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
函数 实现屏幕拖动

function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
set(gcf,'Pointer','fleur');
handles.BtnDown=1;
p=get(gca,'currentpoint'); 
handles.BtnDownPt(1)=p(1);
handles.BtnDownPt(2)=p(3);
guidata(hObject, handles);

function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
set(gcf,'Pointer','fleur');
handles.BtnDown=1;
p=get(gca,'currentpoint'); 
handles.BtnDownPt(1)=p(1);
handles.BtnDownPt(2)=p(3);
guidata(hObject, handles);

function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
p=get(gca,'currentpoint'); 
if handles.BtnDown==1
    center(1)=handles.center(1)-p(1)+handles.BtnDownPt(1);
    center(2)=handles.center(2)-p(3)+handles.BtnDownPt(2);
    axis([0 1 0 1]+[center(1) center(1) center(2) center(2)]);
    handles.center=center;
    guidata(hObject, handles);
end
p(1)=vpa(p(1),3);
p(3)=vpa(p(3),3);
set(findobj(gcf,'tag','text8'),'String',p(1));
set(findobj(gcf,'tag','text9'),'String',p(3));

程序效果图:
来源:http://blog.csdn.net/wjabcjw/article/details/3073886

你可能感兴趣的:(String,function,matlab,plot)