필터 지우기
필터 지우기

What is the difference between setappdata() and set(handles)?

조회 수: 3 (최근 30일)
Firzi Mukhri
Firzi Mukhri 2013년 5월 24일
I'm new with GUIDE and would like to know what the difference between setappdata() and set().
For example I have a variable handles.response = 0, when a push button is pressed I would like the value to change to 5. So in the push button callback I write:
function G_Callback(hObject, eventdata, handles)
% hObject handle to G (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
G=5;
set (handles.response,'String',G);
guidata(hObject,handles);
Is it the same with setappdata if I write:
function G_Callback(hObject, eventdata, handles)
% hObject handle to G (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
G=5;
setappdata (0,'handles.response',G);
guidata(hObject,handles);
Thank you.

채택된 답변

Jan
Jan 2013년 5월 24일
setappdata sets the value of the 'ApplicationData' field of the figure, while set can set the value of all fields of any kind of handle graphic objects. In your example set is used to define the 'String' property of the object with the handle stored in handles.response. But the struct handles (which has a confusing name, because it can contain everything and not only handles) is stored by guidata(), which is a wrapper for setappdata and getappdata for convenience.
Even setappdata(Handle, Name, Value) is a wrapper for:
S = get(Handle, 'ApplicationData');
S.(Name) = Value;
set(Handle, 'ApplicationData', S);
Using setappdata(0, ...) stores values in the application data of the root object, which means the command window. This is a kind of global variable with the usual difficulties.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by