Verfasst am: 09.07.2010, 15:59
Titel: Variable wird nicht erkannt
Ich möchte eine Variable, die durch ein Textfeld im GUI eingegeben wird, weiter verwenden um etwas zu berechnen. Leider komtt dabei immer der Fehler, das die variable nicht bekannt ist.
Hier der code:
Code:
functionvarargout = Top_Load_1(varargin) % TOP_LOAD_1 M-file for Top_Load_1.fig % TOP_LOAD_1, by itself, creates a new TOP_LOAD_1 or raises the existing % singleton*.
%
% H = TOP_LOAD_1 returns the handle to a new TOP_LOAD_1 or the handle to % the existing singleton*.
%
% TOP_LOAD_1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TOP_LOAD_1.M with the given input arguments.
%
% TOP_LOAD_1('Property','Value',...) creates a new TOP_LOAD_1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Top_Load_1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Top_Load_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 Top_Load_1
% Last Modified by GUIDE v2.5 09-Jul-2010 10:03:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Top_Load_1_OpeningFcn, ...
'gui_OutputFcn', @Top_Load_1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Top_Load_1 is made visible. function Top_Load_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 Top_Load_1 (see VARARGIN)
% Choose default command line output for Top_Load_1
handles.output = hObject;
% UIWAIT makes Top_Load_1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Top_Load_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;
function length_Callback(hObject, eventdata, handles) % hObject handle to length (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 length as text % str2double(get(hObject,'String')) returns contents of length as a double
handles.Wert_length = str2double(get(hObject,'String'));
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function length_CreateFcn(hObject, eventdata, handles)
% hObject handle to length (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 try
handles.Wert_length = Wert_length;
set(hObject,'String',handles.Wert_length);
catch end guidata(hObject,handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function width_Callback(hObject, eventdata, handles) % hObject handle to width (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 width as text % str2double(get(hObject,'String')) returns contents of width as a double
handles.Wert_width = str2double(get(hObject,'String'));
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function width_CreateFcn(hObject, eventdata, handles) % hObject handle to width (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 try
handles.Wert_width = Wert_width;
set(hObject,'String',handles.Wert_width);
catch end guidata(hObject,handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function heigth_Callback(hObject, eventdata, handles) % hObject handle to heigth (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 heigth as text % str2double(get(hObject,'String')) returns contents of heigth as a double
% --- Executes during object creation, after setting all properties. function heigth_CreateFcn(hObject, eventdata, handles) % hObject handle to heigth (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 try
handles.Wert_heigth = Wert_heigth;
set(hObject,'String',handles.Wert_heigth);
catch end guidata(hObject,handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in calculate. function calculate_Callback(hObject, eventdata, handles) % hObject handle to calculate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
kannst du vielleicht nochmal den Callback rauskopieren, um den es geht? Ohne fig-File ist das ganze ja nicht lauffähig, und durch den ganzen Code durchzugehen ist doch etwas mühsam.
function length_Callback(hObject, eventdata, handles) % hObject handle to length (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 length as text % str2double(get(hObject,'String')) returns contents of length as a double
handles.Wert_length = str2double(get(hObject,'String'));
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties. function length_CreateFcn(hObject, eventdata, handles)
% hObject handle to length (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 try
handles.Wert_length = Wert_length;
set(hObject,'String',handles.Wert_length);
catch end
% --- Executes on button press in calculate. function calculate_Callback(hObject, eventdata, handles) % hObject handle to calculate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Die Definitionen für ein GUI verstehe ich noch nicht ganz.
Hat jemand ein laufähiges Beispiel mit einem GUI?
Ein Wert soll eingetragen werden, danach wir etwas berechnet und anschliessend das Resultat im GUI wieder dargestellt.
bitte schreib doch die Fehlermeldung dazu. Hellsehen ist leider nicht meine Stärke Oder doch?? Bei handle fehlt ein s. Da hätte man nun auch selber draufkommen können, oder?
Sorry war mein Fehler es scheint wirklich zu funktionieren. Nicht für Ungutes. Danke für die Hilfe
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.