Verfasst am: 23.11.2009, 14:03
Titel: Timer Function: Too many input arguments
Hilfe, bitte kann mir jemand helfen!!
Ich habe folgendes Problem:
Zur eleganteren Handhabung einer timer-function möchte ich dieser mithilfe eines GUIs starten. Dabei (in der eigentlichen Funktion) geht es darum, externe Daten mithilfe von analoginput zu erfassen und zu plotten.
Die sich verändernden Daten sollen dabei in Form eines Punktes auf bestehende Kurvenverläufe, die in einer MAT-File hinterlegt sind, draufgeplottet werden.
Code:
%
% PISTPOS3
%
% Funktion zum Erkennen der Kolbenposition mittels Drehpotentiometer % % Diese Funktion erhält über "analoginput" (s. Zeile 25) Daten aus der Messkarte % (National Instruments, M-Serie) und gibt sie abhängig von der Kolben- % bzw. Kurbelwellenposition als Punkt auf dem Verlauf der Motorgrößen % (Zylindertemperatur, Zylinderdruck, Masse im Zylinder, % Ventilerhebungskurven und p-V-Diagramm) aus. % % Datum: % Verfasser: Benjamin Fahrentholz
%
% Lehrstuhl für Verbrennungskraftmaschinen der TU München
Wenn ich den Timer mithilfe des GUIs (von der opening-function aus) starten möchte bekomme ich immer wieder die Fehlermeldung:
"Too many input arguments"!!!
GUI:
Code:
functionvarargout = User_Interface2(varargin) % USER_INTERFACE2 M-file for User_Interface2.fig % USER_INTERFACE2, by itself, creates a new USER_INTERFACE2 or raises the existing % singleton*.
%
% H = USER_INTERFACE2 returns the handle to a new USER_INTERFACE2 or the handle to % the existing singleton*.
%
% USER_INTERFACE2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in USER_INTERFACE2.M with the given input arguments.
%
% USER_INTERFACE2('Property','Value',...) creates a new USER_INTERFACE2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before User_Interface2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to User_Interface2_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 User_Interface2
% Last Modified by GUIDE v2.5 17-Nov-2009 12:46:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @User_Interface2_OpeningFcn, ...
'gui_OutputFcn', @User_Interface2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before User_Interface2 is made visible. function User_Interface2_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 User_Interface2 (see VARARGIN)
% pistpos3(handles)
%Handle=handles;
%p = zeros(6,1); % Handles auf Punkte
t = timer('TimerFcn',@pistpos3,'ExecutionMode','fixedDelay','BusyMode','queue','Period',0.8,'UserData', handles);
start(t)
% UIWAIT makes User_Interface2 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = User_Interface2_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 pushbutton_Start. function[status]=pushbutton_Start_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
chckstrt=1;
statuscheck
%start(handles.t);
% --- Executes on button press in pushbutton_Stop. function[status]=pushbutton_Stop_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_Stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
%stop(handles.t);
statuscheck
function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (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 edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (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 edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (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
function edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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
function edit5_Callback(hObject, eventdata, handles) % hObject handle to edit5 (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 edit5 as text % str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles) % hObject handle to edit5 (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
function edit6_Callback(hObject, eventdata, handles) % hObject handle to edit6 (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 edit6 as text % str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles) % hObject handle to edit6 (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
Zur besseren Übersicht hier noch einmal meine Quelltexte:
Code:
% User interface functionvarargout = User_Interface2(varargin) % USER_INTERFACE2 M-file for User_Interface2.fig % USER_INTERFACE2, by itself, creates a new USER_INTERFACE2 or raises the existing % singleton*.
%
% H = USER_INTERFACE2 returns the handle to a new USER_INTERFACE2 or the handle to % the existing singleton*.
%
% USER_INTERFACE2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in USER_INTERFACE2.M with the given input arguments.
%
% USER_INTERFACE2('Property','Value',...) creates a new USER_INTERFACE2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before User_Interface2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to User_Interface2_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 User_Interface2
% Last Modified by GUIDE v2.5 17-Nov-2009 12:46:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @User_Interface2_OpeningFcn, ...
'gui_OutputFcn', @User_Interface2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before User_Interface2 is made visible. function User_Interface2_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 User_Interface2 (see VARARGIN)
% pistpos3(handles)
%Handle=handles;
%p = zeros(6,1); % Handles auf Punkte
t = timer('TimerFcn',{@pistpos3,handles},'ExecutionMode','fixedDelay','BusyMode','queue','Period',0.8);
start(t)
% UIWAIT makes User_Interface2 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = User_Interface2_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 pushbutton_Start. function[status]=pushbutton_Start_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_Start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
chckstrt=1;
statuscheck
%start(handles.t);
% --- Executes on button press in pushbutton_Stop. function[status]=pushbutton_Stop_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_Stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
%stop(handles.t);
statuscheck
function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (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 edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (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 edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (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
function edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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
function edit5_Callback(hObject, eventdata, handles) % hObject handle to edit5 (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 edit5 as text % str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles) % hObject handle to edit5 (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
function edit6_Callback(hObject, eventdata, handles) % hObject handle to edit6 (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 edit6 as text % str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles) % hObject handle to edit6 (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
% pistpos 3 % PISTPOS3
%
% Funktion zum Erkennen der Kolbenposition mittels Drehpotentiometer % % Diese Funktion erhält über "analoginput" (s. Zeile 25) Daten aus der Messkarte % (National Instruments, M-Serie) und gibt sie abhängig von der Kolben- % bzw. Kurbelwellenposition als Punkt auf dem Verlauf der Motorgrößen % (Zylindertemperatur, Zylinderdruck, Masse im Zylinder, % Ventilerhebungskurven und p-V-Diagramm) aus. % % Datum: % Verfasser: Benjamin Fahrentholz
%
% Lehrstuhl für Verbrennungskraftmaschinen der TU München
kannst du vielleicht deine m-files und fig-files anhängen,
damit man es selbst ausprobieren kann.
MATLAB-Novize
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 30.11.2009, 14:10
Titel: Timer Function: Too many input arguments
Das würde wahrscheinlich schwierig werden, weil du dazu auch noch die Messkarte zur Generierung der Daten benötigst.
Aber inzwischen hats geklappt! Vielen Dank noch einmal für den super Tipp!
Es hat wirklich nur daran gelegen, dass ich der Timer-Funktion nicht das handle übergeben hatte.
Ich wusste bis zu deiner Antwort nicht, dass ich das in geschweifte Klammern schreiben muss...
Dann freue mich. dass du es selbst herausgefunden hast.
Weiterhin Viel Erfolg!
Liz
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 11.05.2010, 18:07
Titel: ??? Error while evaluating TimerFcn for timer
Der Thread ist zwar schon etwas älter... aber ich bin nun beim Erstellen meiner GUI auf die selbe Fehlermeldung gestossen und bin nach langem Suchen und Probieren immer noch nicht weiter gekommen.
Ich soll eine GUI zu einer Simulink-Simulation erstellen, mit der ich dann auf Parameter einer S-Funktion zugreife. Nun möchte ich gerne, wenn ich die Simulation mit meinem Button starte auch einen Timer starten, der mir die verstrichene Zeit in einem Textfeld ausgibt.
Zunächst habe ich damit angefangen, die Oberfläche mit GUIDE zu erstellen, dwas zu folgender Funktion mit Timer geführt hat (hat auch funktionert):
function[] = updater(varargin)
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'string',z);
set(tmr,'UserData',z);
ifget(handles.sim_start_stop,'Value') == get(handles.sim_start_stop,'Min')
stop(tmr);
delete(tmr);
return end end guidata(meineGUI,handles);
end
%Simulation starten
sim('meineSim',[0 sim_time],simset('DstWorkspace','base'));
ifget_param('meineSim','SimulationStatus')=='stopped'
set(handles.hkl_sim_start_stop, 'State','off');
get_HerzData(hObject);
end
z=0;
set(tmr,'UserData',z);
start(tmr); % Start the timer object.
function updater
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'String',num2str(z));
set(tmr,'UserData',z);
ifget(handles.hkl_sim_start_stop, 'State') == 'off'
stop(tmr);
delete(tmr);
return end end
% Initialize and hide the GUI as it is being constructed.
gui_Position = [0,0,1810,900];
gui_Name = mfilename;
% Simple structure that allows only one instance. iffindobj('type','figure','name',gui_Name) close(findobj('type','figure','name',gui_Name));
end
hklGUI = figure('Visible', 'off',...
'Position', gui_Position,...
'Name', gui_Name,...
'Resize', 'on'... );
% Move the GUI to the center of the screen.
movegui(hklGUI,'center')
% contruct the GUI components
%... meine ganzen GUI Komponenten die ich hier jetzt mal der Einfachheit halber weglass....
% Choose default command line output für meineGUI
handles.output = hklGUI;
das mit den {} geschweiften Klammern bei der TimerFcn hatte ich schon probiert... hat das Problem nicht behoben.
Das liegt auch nicht an geschweiften klammern, sondern an fehlenden Parametern:
Wenn du z.B. TimerFcn ,ButtonDownFcn und CallbackFcn definierst
muss in der Funktion 2 Übergabeparameter immer definiert sein.
es wäre richtig:
Code:
function updater(timer_handle, eventdata)
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'String',num2str(z));
set(tmr,'UserData',z);
ifget(handles.hkl_sim_start_stop, 'State') == 'off'
stop(tmr);
delete(tmr);
return end end
oder VARARGIN, dass eine Art Container, welcher beliebige Anzahl Eingaben akzeptiert.
Code:
function updater(varargin)
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'String',num2str(z));
set(tmr,'UserData',z);
ifget(handles.hkl_sim_start_stop, 'State') == 'off'
stop(tmr);
delete(tmr);
return end end
??? Error while evaluating TimerFcn for timer 'simtime'
Matrix dimensions must agree.
was soll ich ihm denn übergeben? Hab echt so langsam nen Knoten im Hirn sorry ;[
Liz
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 11.05.2010, 22:18
Titel:
Also Danke erstmal für die schnelle Antwort. Hab's mir nach ner Pause nochmal angeschaut und natürlich hatte denny Recht.
Konnte auch herausfinden woran der zweite Fehler lag. Deshalb zur Info nochmal für Dummies wie mich.
Habe zunächst bei der 'TimerFcn', {@updater,handles} belegt und folgendes übergeben:
Code:
function updater(tmr, eventdata, handles)
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'String',num2str(z));
set(tmr,'UserData',z);
ifget(handles.hkl_sim_start_stop, 'State') == 'off'
stop(tmr);
delete(tmr);
return end end
wenn hkl_sim_start_stop ein toggletool der uitoolbar ist.
Geht man aber über ein StringCompare funktioniert die Sache allerdings:
Code:
function updater(tmr, eventdata, handles,varargin)
x=get(handles.hkl_sim_start_stop, 'State');
u = 'off';
z = get(tmr,'UserData');
z = z + 1;
set(handles.time_elapsed,'String',z);
set(tmr,'UserData',z);
ifstrcmp(x,u)
stop(tmr);
delete(tmr);
return end
So läuft der Timer und wird auch brav gestoppt wenn ich mein ToggleTool erneut betätige.
Bestimmt gibt's dafür auch ne elegantere Lösung aber es funktioniert erstmal.
Liz
Gast
Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
Verfasst am: 11.05.2010, 22:21
Titel:
...sollte mir wohl doch nen Account hier zulegen, dann kann ich meine Posts auch editieren.
nach dem ersten Codebrocken fehlt:
Dann läuft die TimerFcn aber nur einmal...
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.