Verfasst am: 26.01.2016, 09:19
Titel: Setzen von mehreren Variablen durch ein popupmenu
Hallo zusammen,
ich habe ein Problem bei der Programmierung des Interfaces zu meinem Programm.
Es geht um folgenden Code
Code:
% --- Executes on selection change in popupmenuform. function popupmenuform_Callback(hObject, eventdata, handles) % hObject handle to popupmenuform (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 popupmenuform contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenuform
% --- Executes on button press in pushbuttonstart. function pushbuttonstart_Callback(hObject, eventdata, handles) % hObject handle to pushbuttonstart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
length = str2num(get(handles.editlength,'String'));
linearfeedrate = str2num(get(handles.editlinearfeedrate,'String'));
width = str2num(get(handles.editwidth,'String'));
frequency = str2num(get(handles.editfrequency,'String'));
frequencyratio = %HIER SOLLEN DIE VARIABLEN ÜBERNOMMEN WERDEN
phaseshift = %HIER SOLLEN DIE VARIABLEN ÜBERNOMMEN WERDEN
name = 'test'
% --- Executes on selection change in popupmenuform. function popupmenuform_Callback(hObject, eventdata, handles) % hObject handle to popupmenuform (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 popupmenuform contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenuform
case3
handles.frequencyratio = 1/2
handles.phaseshift = 0 otherwise end % save the changes to the structure guidata(gcbo,handles);
end
% --- Executes on button press in pushbuttonstart. function pushbuttonstart_Callback(hObject, eventdata, handles) % hObject handle to pushbuttonstart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in popupmenuform. function popupmenuform_Callback(hObject, eventdata, handles) % hObject handle to popupmenuform (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 popupmenuform contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenuform
case1
handles.frequencyratio = 1;
handles.phaseshift = pi/2;
% save the changes to the structure guidata(gcbo,handles);
case2
handles.frequencyratio = 2;
handles.phaseshift = 0;
% save the changes to the structure guidata(gcbo,handles);
case3
handles.frequencyratio = 1/2;
handles.phaseshift = 0;
% save the changes to the structure guidata(gcbo,handles);
otherwise end
% --- Executes on button press in pushbuttonstart. function pushbuttonstart_Callback(hObject, eventdata, handles) % hObject handle to pushbuttonstart (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Das verstehe ich ehrlich gesagt nicht ganz. Evtl. ist das so eine Sache von guide, welcher ja deinen Code erzeugt hat. Normalerweise muss eine
function
mit end abgeschlossen werden, was hier aber eindeutig fehlt oder nicht sichtbar ist.
Code:
function popupmenuform_Callback(hObject, eventdata, handles)
Du musst handles.frequencyratio initialisieren. Am besten in der OpeningFcn, so fern du mit guide arbeitest:
Code:
function MYGUI_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 unrecognized PropertyName/PropertyValue pairs from the % command line (see VARARGIN)
% Choose default command line output for untitled2
handles.output = hObject;
% hier Daten initialisieren
handles.frequencyratio = 0;
handles.phaseshift = 0;
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.