概述
现在主要的代码部分已经完成,但是在WindowButtonMotionFcn部分一直读取不了前面的一个句柄的值,不知道为什么,代码如下:
function varargout = untitled1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn, ...
'gui_OutputFcn', @untitled1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled1 is made visible.
function untitled1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled1_OutputFcn(hObject, eventdata, handles)
handles.Guideline='N';
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.xls', 'Pick an M-file');
str=[pathname,filename];
y=xlsread(str,'B:B');
[h,l]=size(y);
s=1:1:h;
handles.Data=plot(s,y);
handles.h=h;
handles.l=l;
hold on;
X1=str2num(get(handles.edit1,'String'));
X2=str2num(get(handles.edit2,'String'));
handles.HLine= plot([X1, X1],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine_ButtonDown,handles});
handles.HLine2= plot([X2, X2],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine2_ButtonDown,handles});
set(gcf,'WindowButtonMotionFcn',@fig_WindowButtonMotionFcn);
set(gcf,'WindowButtonMotionUpFcn',@fig_WindowButtonUpFcn);
guidata(hObject,handles)
function edit1_Callback(hObject, eventdata, handles)
X1=str2num(get(handles.edit1,'String'));
handles.HLine= plot([X1, X1],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine_ButtonDown,handles});
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
X2=str2num(get(handles.edit2,'String'));
handles.HLine= plot([X2, X2],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine_ButtonDown,handles});
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fig_WindowButtonUpFcn(hObject, eventdata, handles)
handles.Guideline='N';
ss=41;
guidata(hObject, handles);
function HLine_ButtonDown(hObject, eventdata, handles)
handles.Guideline='HLine';
ss=11;
guidata(hObject, handles);
function HLine2_ButtonDown(hObject, eventdata, handles)
handles.Guideline='HLine2';
ss=21
guidata(hObject, handles);
es)
function fig_WindowButtonMotionFcn(hObject,eventdata, handles)
switch handles.Guideline
case 'HLine'
MousePos = get(gca,'CurrentPoint') ;
XPos = MousePos(1,1);
Px=num2str(XPos);
set(handles.edit1,'String',Px);
X1=str2num(get(handles.edit1,'String'));
handles.HLine= plot([X1, X1],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine_ButtonDown,handles});
handles.HLine2= plot([X2, X2],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine2_ButtonDown,handles});
case 'HLine2'
MousePos = get(gca,'CurrentPoint') ;
XPos = MousePos(1,1);
Px=num2str(XPos);
set(handles.edit2,'String',Px);
X2=str2num(get(handles.edit1,'String'));
handles.HLine= plot([X1, X1],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine_ButtonDown,handles});
handles.HLine2= plot([X2, X2],[-1.6,0.4],'r--','ButtonDownFcn',{@HLine2_ButtonDown,handles});
otherwise
end
guidata(hObject, handles);
2018-4-11 13:49 上传
点击文件名下载附件
19.68 KB, 下载次数: 8
2018-4-11 13:49 上传
点击文件名下载附件
4.01 KB, 下载次数: 8
最后
以上就是缓慢书本为你收集整理的matlab鼠标获取曲线上的值,GUI 鼠标拖动直线实时读曲线值的全部内容,希望文章能够帮你解决matlab鼠标获取曲线上的值,GUI 鼠标拖动直线实时读曲线值所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复