Ich bin absoluter Matlab Neuling und wollte zum Üben ein Programm schreiben, mit dem 3 verschiedene Funktionen über Radio Buttons auswählbar sind und 3 verschiedene Parameter eingegeben werden können, die in den Funktionen verwendet werden.
Die jeweilige Funktion soll in einem extra Fenster geplottet werden.
Nun habe ich Probleme meine eingegeben Parameter richtig zu übergeben...
An sich habe ich einfach für jede Funktion in der der Parameter verwendet wird diesen Global definiert, irgendwo muss allerdings noch ein Fehler liegen....
Wäre echt super wenn mal jemand über meinen kurzen Code schauen könnte...
% TEST6 M-file for test6.fig % TEST6, by itself, creates a new TEST6 or raises the existing % singleton*.
%
% H = TEST6 returns the handle to a new TEST6 or the handle to % the existing singleton*.
%
% TEST6('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TEST6.M with the given input arguments.
%
% TEST6('Property','Value',...) creates a new TEST6 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before test6_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to test6_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 test6
% Last Modified by GUIDE v2.5 22-Sep-2010 09:10:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test6_OpeningFcn, ...
'gui_OutputFcn', @test6_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before test6 is made visible. function test6_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 test6 (see VARARGIN) global a;
global b;
global c;
a=1;
b=1;
c=1;
% Choose default command line output for test6
handles.output = hObject;
figure;
t = 0:0.1:2*pi;
x = 1; y = 1;
plot(x, y, 'r');
axis equal;
% UIWAIT makes test6 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = test6_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 edit1_Callback(hObject, eventdata, handles)
global a;
global b;
global c;
% 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
a = get(handles.edit1, 'String');
%set(handles.text1, 'String', txt);
% --- 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. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
global a;
global b;
global c;
% 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
b = get(handles.edit2, 'String');
% --- 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)
global a;
global b;
global c;
% 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
c = get(handles.edit3, 'String');
% --- 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
% --- Executes when selected object is changed in uipanel1. function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
global a;
global b;
global c;
% hObject handle to the selected object in uipanel1 % eventdata structure with the following fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle of the previously selected object or empty if none was selected % NewValue: handle of the currently selected object
switchget(hObject,'Tag')% Get Tag of selected object case 'radiobutton1'
% Code for when radiobutton1 is selected.
figure;
t = 0:0.1:2*pi;
x = t; y=a*t;
plot(x, y, 'r');
% axis equal;
case 'radiobutton2'
% Code for when radiobutton2 is selected.
figure;
t = 0:0.1:2*pi;
x = t; y = (a*cos(b*t)+c);
plot(x, y, 'r');
%axis equal;
case 'radiobutton3'
% Code for when togglebutton1 is selected.
figure;
t = 0:0.1:2*pi;
x = t; y =a*b*t;
plot(x, y, 'r');
%axis equal;
otherwise % Code for when there is no match. warning('Fall bei Aufruf Radio Buttons vergessen!');
end
% handles structure with handles and user data (see GUIDATA)
Du schreibst, dass "irgendwo ein Fehler liegen muss".
Es wäre gut, wenn Du den Fehler suchst und ihn zumindest beschreibst. Gibt es eine Fehlermeldung? Welche? Weichen die Ergebnisse von Deinen Erwartungen ab? Welche?
Ich löse in diesem Forum gerne Probleme, aber ich habe wenig Lust die Probleme auch noch finden zu müssen. Darum bitte ich Dich um mehr (zumindest irgendwelche) Details.
Freundliche Grüße, Jan
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.