Getappdata and setappdata
4 次查看(过去 30 天)
显示 更早的评论
Hi, I have a problem with getappdata and setappdata. I was wrote the matlab help but I don't understand everything. Do you have any example code with this metods?
0 个评论
采纳的回答
Chandra Kurniawan
2011-12-5
Hello,
I will give you sample code for this topic.
I have a .fig file (figure) that consists of 2 axes (axes1 and axes2) and 2 pushbutton (pushbutton1 and pushbutton2).
Then, here the m-file code
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
I = imread('cameraman.tif');
imagesc(I, 'parent', handles.axes1);
setappdata(handles.pushbutton1,'img',I);
function pushbutton2_Callback(hObject, eventdata, handles)
J = getappdata(handles.pushbutton1,'img');
bw = im2bw(J);
imagesc(bw, 'parent', handles.axes2);
Watch at pushbutton1_callback. Fisrt I read image with command imread and display it to the axes1.
Then after finished, I store the variable I to the handle : 'pushbutton1' as name : 'img' with command :
setappdata(handles.pushbutton1,'img',I);
Then watch at pushbutton2_callback
I used command
J = getappdata(handles.pushbutton1,'img');
to get the the last value which I stored at handle 'pushbutton1' which name = 'img'.
And then I successfully create a binary image with input parameter 'J'
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!