Getappdata and setappdata
조회 수: 9 (최근 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개)
Paulo Silva
2011년 12월 5일
편집: John Kelly
2014년 6월 12일
Matlab GUI: Handling User Data and Images>
댓글 수: 0
참고 항목
카테고리
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!