Ich hab ein kleines Problem...
Ich hab mir ne kleine GUI gebaut in der es 2 Buttons und ein popup gibt.
Ein Exit button und ein Strat button.
Ich möchte gerne mit dem Popup ein "Matlabskript" auswählen und dann wenn ich auf den Start knopf drücke soll dieses ausgeführt werden.
Wie kann ich das bewerkstelligen??
Hier mal meine GUI ist über guide erstellt...
Code:
functionvarargout = Bsp_1(varargin) % BSP_1 M-file for Bsp_1.fig % BSP_1, by itself, creates a new BSP_1 or raises the existing % singleton*.
%
% H = BSP_1 returns the handle to a new BSP_1 or the handle to % the existing singleton*.
%
% BSP_1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in BSP_1.M with the given input arguments.
%
% BSP_1('Property','Value',...) creates a new BSP_1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Bsp_1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Bsp_1_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 Bsp_1
% Last Modified by GUIDE v2.5 06-Mar-2013 14:22:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Bsp_1_OpeningFcn, ...
'gui_OutputFcn', @Bsp_1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Bsp_1 is made visible. function Bsp_1_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 Bsp_1 (see VARARGIN)
% Choose default command line output for Bsp_1
handles.output = hObject;
set(handles.popupmenu1,'string',{'Auswertung von Stromverläufen','Auswertung von Bildern'});
handles.z=hObject;
handles.z=0;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes Bsp_1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Bsp_1_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 button press in Startknopf. function Startknopf_Callback(hObject, eventdata, handles) % hObject handle to Startknopf (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.z=handles.z+1;
guidata(hObject,handles) %Update handles structure
Auswertung;
set(handles.Ausgabe,'String',num2str(handles.z));%Ausgabe
% --- Executes on button press in Exit. function Exit_Callback(hObject, eventdata, handles) % hObject handle to Exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close;
% --- 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
pop_val=get(hObject,'value');
% 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
Das ist noch eine recht allgemeine Frage, so dass eine konkrete Antwort mit Raterei und viel Aufwand verbunden wäre. Je konkreter die Frage, desto leichter und passender die Antwort.
Wie könnte denn das Popup-Menü mit den Namen der Matlab-Skript befüllt werden?
Ich hab die Namen der Matlabskripte selber rein geschrieben per hand..
Code:
% Choose default command line output for Bsp_1
handles.output = hObject;
set(handles.popupmenu1,'string',{'Auswertung von Stromverläufen','Auswertung von Bildern'});
fand das am einfachsten
eigentlich ist meine Frage wie bekomm ich das hin wenn ich im Popupmenü
'Auswertung von Stromverläufen' auswähle und ich dann auf den Startbutton drücke der ja über
Code:
function Startknopf_Callback(hObject, eventdata, handles) % hObject handle to Startknopf (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.z=handles.z+1;
guidata(hObject,handles) %Update handles structure
Auswertung;
set(handles.Ausgabe,'String',num2str(handles.z));%Ausgabe
switch str{val} case 'Auswertung von Stromverläufen'
% hier entsprechende Fkt. aufrufen case 'Auswertung von Bildern'
% hier entsprechende Fkt. aufrufen end
Ich bekomm ímmer eine Fehlermeldung wenn ich das Popup benutze... er macht zwar das was er soll aber dennoch...
Fehlermeldung:
??? Error using ==> feval
Undefined function or method 'popupmenu1_Callback' for input
arguments of type 'struct'.
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Bsp_1 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Bsp_1('popupmenu1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Ich poste mal mein code und die figure...
muss nämlich gestehen so richtig steige ich mit den GUI noch nicht druch...
Code:
functionvarargout = Bsp_1(varargin) % BSP_1 M-file for Bsp_1.fig % BSP_1, by itself, creates a new BSP_1 or raises the existing % singleton*.
%
% H = BSP_1 returns the handle to a new BSP_1 or the handle to % the existing singleton*.
%
% BSP_1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in BSP_1.M with the given input arguments.
%
% BSP_1('Property','Value',...) creates a new BSP_1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Bsp_1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Bsp_1_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 Bsp_1
% Last Modified by GUIDE v2.5 06-Mar-2013 14:22:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Bsp_1_OpeningFcn, ...
'gui_OutputFcn', @Bsp_1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Bsp_1 is made visible. function Bsp_1_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 Bsp_1 (see VARARGIN)
% Choose default command line output for Bsp_1
handles.output = hObject;
set(handles.popupmenu1,'string',{'Auswertung von Stromverläufen','Auswertung von Bildern'});
% UIWAIT makes Bsp_1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Bsp_1_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 button press in Startknopf. function Startknopf_Callback(hObject, eventdata, handles) % hObject handle to Startknopf (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) guidata(hObject,handles) %Update handles structure
val=get(handles.popupmenu1,'value');
str=get(handles.popupmenu1,'string');
switch str{val} case 'Auswertung von Stromverläufen'
Auswertung;
case 'Auswertung von Bildern'
Florreneu;
end
% --- Executes on button press in Exit. function Exit_Callback(hObject, eventdata, handles) % hObject handle to Exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close;
% --- 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 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 = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1
und schon geht es...
hoffe das ist richtig scheint aber so...
Ich glaube für die GUI-Programmierung brauch ich wohl noch ein wenig Zeit bis ich die halbwegs gut verstehe...
Danke für die Hilfe
LG Florre
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.