How to use Setappdata/ Getappdata

13 visualizzazioni (ultimi 30 giorni)
Felix Oestrech
Felix Oestrech il 27 Ago 2018
Risposto: Felix Oestrech il 27 Ago 2018
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.

Risposte (1)

Felix Oestrech
Felix Oestrech il 27 Ago 2018
% % --------------------------------------------------------------------
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?

Categorie

Scopri di più su Maintain or Transition figure-Based Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by