希望任何人都可以帮助我。
我尝试在我的 GUI 中加载和显示图像。之后我激活datacursormode。现在我想从我的数据游标对象中提取位置并将信息保存到全局变量中以处理这些数据。
这是我的代码:
function varargout = myGui(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @myGui_OpeningFcn, ...
'gui_OutputFcn', @myGui_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 myGui is made visible.
% Choose default command line output for myGui
handles.output = hObject;
path = uigetimagefile;
img = imread(path);
axes(handles.axes1);
imshow(img);
dcm_obj = datacursormode(handles.figure1);
datacursormode on;
set(dcm_obj,'UpdateFcn', @myupdatefcn );
handles.pos = hObject;
handles.pos = get(0,'userdata');
set(handles.txt1,'String',num2str(handles.pos));
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = myGui_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
在一个额外的 .m 文件中,我有像这样的“myupdatefcn”
function txt = myupdatefcn(~, event_obj)
posi = event_obj.Position;
disp(['You clicked X:',num2str(posi(1)),', Y:',num2str(posi(2))]);
txt = {'Point to Compute'};
set(0,'userdata',posi(1));
end
谁能解释我如何做到这一点?
谢谢