hope anyone can help me.
I try to load and display a image in my GUI. After that i activate datacursormode. Now I want to extract the position from my datacursor object and save the informations into a global variable to work on this data.
Here is my code:
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;
And in a extra .m file i have the 'myupdatefcn' like thi
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
Can anyone explane how I can do this?
thanks
See Question&Answers more detail:os