WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Popup Menü mit geladenen Daten füllen.

 

Newbenoob
Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 04.10.2013, 13:38     Titel: Popup Menü mit geladenen Daten füllen.
  Antworten mit Zitat      
Hallo liebe Community,

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:

function varargout = 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',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- 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;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Testgui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = 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)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
load kombinationen_MAARSY_2010
contents = cellstr(get(hObject,'String'))
contents{get(hObject,'Value')}

% --- 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.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','red');
end
 

Habe mein Gui mit guide erstellt.

Liebe Grüße
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.495
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 04.10.2013, 14:04     Titel:
  Antworten mit Zitat      
Hallo,

vermutlich sollen die Daten von Anfang an in dem Popupmenü stehen? Dann würde ich in der OpeningFcn
Code:
set(handles.popupmenu1, 'String', ...)

verwenden. Das "..." hängt davon ab, wie die Daten in der .mat-Datei heißen und in welcher Form sie vorliegen.

In popupmenu1_callback sollte man dann auf die Nutzereingaben reagieren.

Grüße,
Harald
Private Nachricht senden Benutzer-Profile anzeigen
 
Newbenoob
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 07.10.2013, 10:31     Titel:
  Antworten mit Zitat      
Danke sehr,

funktioniert soweit.
Private Nachricht senden Benutzer-Profile anzeigen
 
Newbenoob
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 08.10.2013, 13:38     Titel:
  Antworten mit Zitat      
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?

Hier einige Infos:

Funktion sieht so aus:
Code:

function[Values,NrKombi]=WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)
 

Kombi ist vorgegeben. Bereich und Fieldname sollen vom Benutzer gewählt werden.

Müsste ja dann ca. so aussehen, oder?
Code:

function[Values] = WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)
get(handles.popupmenu1,'String')
set(handles.popupmenu2,'String',Values)
 

Geht leider so nicht, dadurch wird mir zwar kein Fehler angezeigt, aber in dem 2. PopupMenü erscheint nichts.
Private Nachricht senden Benutzer-Profile anzeigen
 
Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 08.10.2013, 15:35     Titel:
  Antworten mit Zitat      
Hallo Newbenoob,
Zitat:
Müsste ja dann ca. so aussehen, oder?
Code:
function[Values] = WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)
get(handles.popupmenu1,'String')
set(handles.popupmenu2,'String',Values)

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.

Vielleicht meinst Du:
Code:
Values = WerteEigenschaftenNeu(Kombi,Bereich,Fieldname);
set(handles.popupmenu2,'String',Values);

Ich vermute, Du müsstest den ganzen Callback zeigen, damit wir den Zusammenhang nachvollziehen können.

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
Newbenoob
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 08.10.2013, 15:58     Titel:
  Antworten mit Zitat      
Hallo Jan,

"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:

function varargout = 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',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- 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;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Testgui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = 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
if ispc && 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');

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

 
Private Nachricht senden Benutzer-Profile anzeigen
 
Newbenoob
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 09.10.2013, 14:54     Titel:
  Antworten mit Zitat      
Code:

function varargout = 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',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- 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;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Testgui3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = 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.
if ispc && 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.
if ispc && 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.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

 
Private Nachricht senden Benutzer-Profile anzeigen
 
Newbenoob
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 17
Anmeldedatum: 19.09.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 10.10.2013, 09:41     Titel:
  Antworten mit Zitat      
Die Funktion die ich aufrufen möchte sieht so aus:

Code:

%%%
function[Values,NrKombi] = WerteEigenschaftenNeu(Kombi,Bereich,Fieldname)

Values={};
NrKombi={};
if nargin<3, Fieldname=''; end
if nargin<2, Bereich  =''; end

for kk=1:length(Kombi)
 
  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
    if isequal(Values{ii},Kombi(kk).(Bereich).(Fieldname))
      Values =Values( 1:len);
      NrKombi=NrKombi(1:len);
      NrKombi{ii}=[NrKombi{ii} kk];
      break
    end  
  end
     
end
%%%
 


Diese soll, nachdem die Auswhal im Popupmenu1 getroffen wurde im Popupmenu2 ausgegeben werden.
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

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
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

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.