MATLAB
% Write a GUI windows titled "Projectile" that has two user
inputs: (1) the
% launch angle (in degrees) of a projectile between 0 and 90
degrees; and
% (2) the veloicty (in m/s) of the projectile between 1 and 20 m/s.
Your
% GUI should use two input boxes in one window, then the user hits
"OK".
% You should have an error message displayed in a window if the
user input
% an angle or velocity out of range. In your "results" window you
should
% restate the vales the user input and the distance traveled should
be
% displayed.
Code:
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
u = str2double(get(handles.edit1, 'string'));
a = str2double(get(handles.edit2, 'string'));
g = 9.80665
res = 0
if (u >= 0 & u <= 20) & (a >= 0 & a <= 90)
angle = (pi/180)*a;
res = ((u^2) * sin(2*angle))/g;
set(handles.edit3, 'string', num2str(res));
else
set(handles.edit3, 'string', 'Input is out of range');
end
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
MATLAB % Write a GUI windows titled "Projectile" that has two user inputs: (1) the %...