How to use Setappdata/ Getappdata

11 次查看(过去 30 天)
Hello, I already found few Questions concerning my question but it does not help me. So what is the problem: I designed two GUI and I would like to make it work if you are changing the name of a pushbutton (used like a tab), in the second GUI it should change the name as well.
So, I already tried:
% --- Executes on button press in pushbutton31. function pushbutton31_Callback(hObject, eventdata, handles) % hObject handle to pushbutton31 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Tabname= get(handles.pushbutton8, 'String'); Daten= getappdata(handles.figure1, Tabname);
-> which means (to me), MatLab will store Tabname of figure 1.
Now, I am changing from GUI1 to GUI2, mfile changes as well.
% --- Executes on button press in pushbutton31.
function pushbutton31_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton31 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
setappdata(handles.figure1, 'Daten', Tabname)
-> with this, I am taking the stored data from figure1 and I am calling especially Tabname.
But it does not work in general. I guess I have a basic problem with the notation or a definition is missing. I am receiving following error message: Undefined function or variable 'Tabname' or Reference to non-existent field. Is there anyone who can explain me how to use this commands right? Or should I use other commands?
I am thankful for every advice.

回答(1 个)

Felix Oestrech
Felix Oestrech 2018-8-27
% % --------------------------------------------------------------------
function Bearbeiten_menu_Tabname_Callback(hObject, eventdata, handles)
% hObject handle to Bearbeiten_menu_Tabname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Gebaeudetyp2= inputdlg( 'Name der Gebäudegruppe' , 'Tabname ändern' );
set(handles.pushbutton22, 'String', Gebaeudetyp2{1} );
Gebaeudetyp2= get(handles.pushbutton22, 'String');
setappdata(0, 'Gebaeudetyp2', Gebaeudetyp2);
end
Gebaeudetyp2= getappdata(0, 'Gebaeudetyp2');
set(handles.pushbutton22, 'String', Gebaeudetyp2);
Finally, I found a solution and it works. Just in case someone else will have a similar problem, I am posting my solution.
I am using this getappdata- command in the opening function. Is it possible to delete the stored value?

类别

Help CenterFile Exchange 中查找有关 Maintain or Transition figure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by