How to use Setappdata/ Getappdata

13 ビュー (過去 30 日間)
Felix Oestrech
Felix Oestrech 2018 年 8 月 27 日
回答済み: Felix Oestrech 2018 年 8 月 27 日
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 Center および File ExchangeMaintain 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