Getappdata and setappdata

14 ビュー (過去 30 日間)
Agata
Agata 2011 年 12 月 5 日
編集済み: John Kelly 2014 年 6 月 12 日
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?

採用された回答

Chandra Kurniawan
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'

その他の回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 12 月 5 日
編集済み: John Kelly 2014 年 6 月 12 日

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by