Programmering i Matlab med GUI
Hej,
Har en uppg. som jag inte riktigt får ordning på..
bifogar en bild för lättare förklaring.. http://imageshack.us/photo/my-images/27/matlaba.jpg/
Jag ska alltså göra ett spel, först välja en siffra på en tärning till vänster.. sen ska en siffra slumpas fram. Är denna "slumpade siffra" samma som den valda så ska satsningen läggas till på bankrullen o tvärtom om den är fel.
Jag har kommit så långt att slumpningen fungerar när man trycker på "Spela!" och att programmet avslutas vid "Slut"
jag håller på vid rad: 150 o få de att samarbeta, alltså den valda siffran med den slumpade för att sedan få upp en msgbox där de står att du vann/förlorade..
Får de inte riktigt att funka ihop.. hur ska jag göra för att lägga till/ta bort satsningen?
Tacksam för hjälp!
function varargout = NYTT_SPEL(varargin)
% NYTT_SPEL MATLAB code for NYTT_SPEL.fig
% NYTT_SPEL, by itself, creates a new NYTT_SPEL or raises the existing
% singleton*.
%
% H = NYTT_SPEL returns the handle to a new NYTT_SPEL or the handle to
% the existing singleton*.
%
% NYTT_SPEL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NYTT_SPEL.M with the given input arguments.
%
% NYTT_SPEL('Property','Value',...) creates a new NYTT_SPEL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before NYTT_SPEL_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to NYTT_SPEL_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 NYTT_SPEL
% Last Modified by GUIDE v2.5 03-Jun-2012 14:39:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @NYTT_SPEL_OpeningFcn, ...
'gui_OutputFcn', @NYTT_SPEL_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before NYTT_SPEL is made visible.
function NYTT_SPEL_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 NYTT_SPEL (see VARARGIN)
% Choose default command line output for NYTT_SPEL
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes NYTT_SPEL wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = NYTT_SPEL_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 checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox2
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject handle to checkbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox3
% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject handle to checkbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox4
% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject handle to checkbox5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox5
% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject handle to checkbox6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox6
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
y=ceil(6*rand);
textptr=findobj(gcbf,'Tag','text3');
for i=1:5
switch y
case 1
set(textptr,'string',1)
case 2
set(textptr,'string',2)
case 3
set(textptr,'string',3)
case 4
set(textptr,'string',4)
case 5
set(textptr,'string',5)
case 6
set(textptr,'string',6)
end
end
H3=findobj(gcbf,'Tag','text3') % Gives handle to the object edit3.
H1=findobj(gcbf,'Tag','checkbox1'); % Gives handle to the object edit1.
tal_1=str2double(get(H1,'String')) % Converts string to number.
H2=findobj(gcbf,'Tag','edit3')
tal_2=str2double(get(H3,'String')) % string till nummer
%if tal_1==tal_2
% msgbox('vinst')
%else tal_1~=tal_2
% msgbox('nitlott!')
if tal_1==tal_2
msgbox('Du vann','Vinst')
else tal_1~=tal_2
msgbox('Fel tal','Försök igen')
%The_sum=(tal_1==tal_2);
set(H2,'String',num2str(The_sum)) % Converts the sum to a string and puts
end
% in edit3
%AA=str2double(checkbox1)
%BB=str2double(text3)
%if AA==BB
% msgbox('Du vann!','Vinst!')
%elseif AA~=BB
% msgbox('NEEJ')
% checkbox1==text3
%A1=findobj(gcbf,'Tag','AA')
%A2=findobj(gcbf,'Tag','BB')
%tal_1=str2double(get(A2,'String'))
%A3=findobj(gcbf,'Tag',msgbox('Hej','Slut'))
%else checkbox1~=text3
% msgbox('Ingen vinst!','Försök igen')
% 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)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
delete(gcbf)
msgbox('Du stängde av spelet!','Avslutat')
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
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.
if ispc && 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.
if ispc && 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.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end