ich möchte ein Gui erstellen, in dem ein popup Menü drin ist. Diese soll mit den Daten aus
kombinationen_MAARSY_2010.mat gefüllt werden.
Wie würde in diesem Fall die Syntax aussehen?
Code:
functionvarargout = Testgui(varargin) % TESTGUI MATLAB code for Testgui.fig % TESTGUI, by itself, creates a new TESTGUI or raises the existing % singleton*.
%
% H = TESTGUI returns the handle to a new TESTGUI or the handle to % the existing singleton*.
%
% TESTGUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TESTGUI.M with the given input arguments.
%
% TESTGUI('Property','Value',...) creates a new TESTGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Testgui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Testgui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Testgui
% Last Modified by GUIDE v2.5 04-Oct-2013 13:28:24
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Testgui_OpeningFcn, ...
'gui_OutputFcn', @Testgui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Testgui is made visible. function Testgui_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Testgui (see VARARGIN)
% Choose default command line output for Testgui
handles.output = hObject;
% UIWAIT makes Testgui wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Testgui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','red');
end
Habe noch eine Frage. Was ich vorhabe ist nun mit der Eingabe aus dem ersten PopupMenü eine Funktion aufzurufen, dessen Werte dann in einem 2. Popupmenü aufgelistet werden.
Es soll also in dem 2 Popupmenü eine Function aufgerufen werden, die auf das erste Popupmenü bezogen ist.
Wie führe ich in einem Callback eine Funktion aus?
Den Code verstehe ich nicht. Wieso wird hier die Funktion "WerteEigenschaftenNeu" nochmal definiert?
"get(handles.popupmenu1,'String')" liest zwar den String aus, weist in aber keiner Variablen zu. Damit ist die Zeile sinnfrei.
"WerteEigenschaftenNeu" ist als Funktion nur einmal definiert. Ich weiß aber nicht so recht, ob ich dich richtig verstanden habe.
Zitat:
Den Code verstehe ich nicht. Wieso wird hier die Funktion "WerteEigenschaftenNeu" nochmal definiert?
"get(handles.popupmenu1,'String')" liest zwar den String aus, weist in aber keiner Variablen zu. Damit ist die Zeile sinnfrei.
Dieser String, also die Auswhal aus dem 1. Popupmenü, soll der Funktion "WerteEigenschaftenNeu" zugewiesen werden.
Code:
functionvarargout = Testgui2(varargin) % TESTGUI2 MATLAB code for Testgui2.fig % TESTGUI2, by itself, creates a new TESTGUI2 or raises the existing % singleton*.
%
% H = TESTGUI2 returns the handle to a new TESTGUI2 or the handle to % the existing singleton*.
%
% TESTGUI2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TESTGUI2.M with the given input arguments.
%
% TESTGUI2('Property','Value',...) creates a new TESTGUI2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Testgui2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Testgui2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Testgui2
% Last Modified by GUIDE v2.5 07-Oct-2013 11:24:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Testgui2_OpeningFcn, ...
'gui_OutputFcn', @Testgui2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Testgui2 is made visible. function Testgui2_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Testgui2 (see VARARGIN) load kombinationen_MAARSY_2010
set(handles.popupmenu1,'String',fieldnames(Kombi(1).Expe));
% Choose default command line output for Testgui2
handles.output = hObject;
% UIWAIT makes Testgui2 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Testgui2_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1
%get(h0bject.popupmenu1,'String')
%Fieldname = set(WerteEigenschaftenNeu,'String','Val') % --- Executes during object creation, after setting all properties.
function[Values] = WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)
%Hier sollen die Werte von PopupMenü eingelesen werden.
set(Fieldname.WerteEigenschaften,'String',Value)
function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER.
%set(handles.popupmenu2,'String','yolo')
%set(handles.popupmenu2,'String','Expe');
ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
functionvarargout = Testgui3(varargin) % TESTGUI3 MATLAB code for Testgui3.fig % TESTGUI3, by itself, creates a new TESTGUI3 or raises the existing % singleton*.
%
% H = TESTGUI3 returns the handle to a new TESTGUI3 or the handle to % the existing singleton*.
%
% TESTGUI3('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TESTGUI3.M with the given input arguments.
%
% TESTGUI3('Property','Value',...) creates a new TESTGUI3 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Testgui3_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Testgui3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Testgui3
% Last Modified by GUIDE v2.5 09-Oct-2013 15:40:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Testgui3_OpeningFcn, ...
'gui_OutputFcn', @Testgui3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Testgui3 is made visible. function Testgui3_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Testgui3 (see VARARGIN) load kombinationen_MAARSY_2010
set(handles.popupmenu1,'String',fieldnames(Kombi(1).Expe));
% Choose default command line output for Testgui3
handles.output = hObject;
% UIWAIT makes Testgui3 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Testgui3_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1
s = get(handles.popupmenu1, 'String');
i = get(handles.popupmenu1, 'Value');
msgbox(['Es wurde "' s{i} '" ausgewählt.'], 'Info');
% --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called function[Values,NrKombi]=WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)
%Hier sollen die Werte von PopupMenü eingelesen werden.
handles.Values = Values;
handles.NrKombi = NrKombi;
guidata(hObject, handles);
set(handles.popupmenu2,'String',Values);
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
if ~isfield(Kombi(kk),Bereich)
AlleBereiche=fieldnames(Kombi(kk));
Nr=listdlg('ListString' ,AlleBereiche,...
'SelectionMode','single',...
'PromptString','Bitte Bereich waehlen:');
Bereich=AlleBereiche{Nr};
end if ~isfield(Kombi(kk).(Bereich),Fieldname)
AlleFieldnames=fieldnames(Kombi(kk).(Bereich));
Nr=listdlg('ListString' ,AlleFieldnames,...
'SelectionMode','single',...
'PromptString','Bitte Feldname waehlen:');
Fieldname=AlleFieldnames{Nr};
end
len=length(Values);
Values{ len+1}=Kombi(kk).(Bereich).(Fieldname); %#ok<AGROW>
NrKombi{len+1}=kk; %#ok<AGROW>
for ii=1:len
ifisequal(Values{ii},Kombi(kk).(Bereich).(Fieldname))
Values =Values(1:len);
NrKombi=NrKombi(1:len);
NrKombi{ii}=[NrKombi{ii} kk];
break end end
Diese soll, nachdem die Auswhal im Popupmenu1 getroffen wurde im Popupmenu2 ausgegeben werden.
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.