5 Textfeilder in denen zufällig (random) die die zahlen 1-5 ausgegeben werden.
Code:
%übergeben der daten aus dem B vektor in die Felder.
[B]=random; % funktion welche mir die 5 zufallszahlen ausgibt set(handles.edit1,'String',num2str(B(1)));
set(handles.edit2,'String',num2str(B(2)));
set(handles.edit3,'String',num2str(B(3)));
set(handles.edit4,'String',num2str(B(4)));
set(handles.edit5,'String',num2str(B(5)));
soweit so gut, das funktioniert.
nun habe ich unter jedem textfeld jeweils einen button. Ziel ist es die "richtige" zahl (bsp:1) zu finden und per button auszuwählen.
nach dem drücken soll nun diese kette nochmal ausgeführt werden (beliebig oft).
mein problem ist aber das wenn ich diese 6 zeilen als funktion schreibe.
bsp:
Code:
%übergeben der daten aus dem B vektor in die Felder.
function do_random();
[B]=random; % funktion welche mir die 5 zufallszahlen ausgibt set(handles.edit1,'String',num2str(B(1)));
set(handles.edit2,'String',num2str(B(2)));
set(handles.edit3,'String',num2str(B(3)));
set(handles.edit4,'String',num2str(B(4)));
set(handles.edit5,'String',num2str(B(5)));
Ich habe nicht diese Funktion gemeint, sondern diese
Code:
%übergeben der daten aus dem B vektor in die Felder.
function do_random();
[B]=random; % funktion welche mir die 5 zufallszahlen ausgibt set(handles.edit1,'String',num2str(B(1)));
set(handles.edit2,'String',num2str(B(2)));
set(handles.edit3,'String',num2str(B(3)));
set(handles.edit4,'String',num2str(B(4)));
set(handles.edit5,'String',num2str(B(5)));
Okay wieder Missverständnis, ich meine natürlich ist diese Funktion eine CALLBACK-Funktion? Wie/Wo rufst du diese Funktion auf?
aber wahrscheinlich rufst aus einer oder mehreren Funktion raus?
Code:
function do_random(handles);
[B]=random; % funktion welche mir die 5 zufallszahlen ausgibt set(handles.edit1,'String',num2str(B(1)));
set(handles.edit2,'String',num2str(B(2)));
set(handles.edit3,'String',num2str(B(3)));
set(handles.edit4,'String',num2str(B(4)));
set(handles.edit5,'String',num2str(B(5)));
function button1_Callback(hObject, eventdata, handles)
do_random(handles)
% MAIN M-file for Main.fig % MAIN, by itself, creates a new MAIN or raises the existing % singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to % the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Main_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Main_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 Main
% Last Modified by GUIDE v2.5 01-Jun-2010 14:49:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Main_OpeningFcn, ...
'gui_OutputFcn', @Main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before Main is made visible. function Main_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 Main (see VARARGIN)
% Choose default command line output for Main
handles.output = hObject;
% UIWAIT makes Main wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. functionvarargout = Main_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;
%
% ausgabe der zufallszahlen an die editfenster
%
[B]=random;
set(handles.edit1,'String',num2str(B(1)));
set(handles.edit2,'String',num2str(B(2)));
set(handles.edit3,'String',num2str(B(3)));
set(handles.edit4,'String',num2str(B(4)));
set(handles.edit5,'String',num2str(B(5)));
%#######################################################################
% Versuch funktion. welche nach dem button ausgeführt werden soll % um neuen random einträge zu machen
function edit1_Callback(hObject, eventdata, handles) % 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
% --- 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) % 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
% --- Executes on button press in pushbutton1. function[a]=pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % auswertung ob die zahl "1" getroffen im feld war. ifget(handles.edit1,'String')==num2str(1);
w_r=1;
else
w_r=0;
end
% Callbacks haben keine Ausgaben % --- Executes on button press in pushbutton1. function[a]=pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % auswertung ob die zahl "1" getroffen im feld war. ifget(handles.edit1,'String')==num2str(1);
w_r=1;
else
w_r=0;
end
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.