Question

In: Computer Science

Using matlab: Build a graphical user interface (GUI) the will read the two corners of a...

Using matlab:

Build a graphical user interface (GUI) the will read the two corners of a rectangle (from the GUI interface) and show the following:

  • A plot of the rectangle (you should have display for it)
  • Show the centroid (the center of the rectangle) on the graph.
  • Calculate the area and the circumference of the triangle (you need to write a function for that).

The interface should have at least the following:

  • Four textboxes to read the ( 2 for each corner of the Rectangle) so the user can enter them
  • At least one command button to start the display and calculations
  • At least one Figure (display).

Solutions

Expert Solution

function varargout = Rectanglex(varargin)
% RECTANGLEX MATLAB code for Rectanglex.fig
% RECTANGLEX, by itself, creates a new RECTANGLEX or raises the existing
% singleton*.
%
% H = RECTANGLEX returns the handle to a new RECTANGLEX or the handle to
% the existing singleton*.
%
% RECTANGLEX('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RECTANGLEX.M with the given input arguments.
%
% RECTANGLEX('Property','Value',...) creates a new RECTANGLEX or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Rectanglex_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Rectanglex_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 Rectanglex

% Last Modified by GUIDE v2.5 17-Feb-2019 10:07:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Rectanglex_OpeningFcn, ...
'gui_OutputFcn', @Rectanglex_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 Rectanglex is made visible.
function Rectanglex_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 Rectanglex (see VARARGIN)

% Choose default command line output for Rectanglex
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Rectanglex wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Rectanglex_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 pushbutton1.
function 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)

%inputs
P1x = str2double(get(handles.P1x,'String'));
P1y = str2double(get(handles.P1y,'String'));
P2x = str2double(get(handles.P2x,'String'));
P2y = str2double(get(handles.P2y ,'String'));


w = abs(P1x - P2x);
h = abs(P1y-P2y);

%diagonal
%plot([P1x P2x],[P1y P2y])
%hold on


%centroid
Cx = (P1x+P2x)/2;
Cy = (P1y+P2y)/2;

plot(Cx,Cy,'x r')

hold on

Xpos = P1x;
Ypos = P1y;

if P1x>P2x
Xpos = P2x;
Ypos = P2y
end


rectangle('Position',[Xpos Ypos w h])



%axis([(min(P1x,P2x)-2) (max(P1x,P2x)+2) (min(P1y,P2y)-2) (max(P1x,P2x)+2)])
xlim([(min(P1x,P2x)-2) (max(P1x,P2x)+2)])
ylim([(min(P1y,P2y)-2) (max(P1y,P2y)+2)])


legend('centroid')
grid on
title('Rectangle')

%Area & circumference

%function handle
Area = @(x,y) x*y;
Circumference = @(x,y) 2*(x+y);


%outputs
set(handles.Area, 'String', Area(w,h));
set(handles.Circumference, 'String', Circumference(w,h));

function P1y_Callback(~, eventdata, handles)
% hObject handle to P1y (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 P1y as text
% str2double(get(hObject,'String')) returns contents of P1y as a double


% --- Executes during object creation, after setting all properties.
function P1y_CreateFcn(hObject, eventdata, handles)
% hObject handle to P1y (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 P2x_Callback(hObject, eventdata, handles)
% hObject handle to P2x (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 P2x as text
% str2double(get(hObject,'String')) returns contents of P2x as a double


% --- Executes during object creation, after setting all properties.
function P2x_CreateFcn(hObject, eventdata, handles)
% hObject handle to P2x (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 P1x_Callback(hObject, eventdata, handles)
% hObject handle to P1x (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 P1x as text
% str2double(get(hObject,'String')) returns contents of P1x as a double


% --- Executes during object creation, after setting all properties.
function P1x_CreateFcn(hObject, eventdata, handles)
% hObject handle to P1x (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 P2y_Callback(hObject, eventdata, handles)
% hObject handle to P2y (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 P2y as text
% str2double(get(hObject,'String')) returns contents of P2y as a double


% --- Executes during object creation, after setting all properties.
function P2y_CreateFcn(hObject, eventdata, handles)
% hObject handle to P2y (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

COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER
PLEASE PLEASE GIVE A THUMBS UP


Related Solutions

For this assignment, you will develop working examples of a graphical user interface (GUI) and event...
For this assignment, you will develop working examples of a graphical user interface (GUI) and event handling and that demonstrate the following: Working code with screenshots of a Python GUI application that includes 5 design widgets of your choosing Working code with screenshots of event handling in Python based on 3 events of your choosing Be sure to include a brief narrative of your code where you explain what the code is doing. Documentation Guidelines: Use good programming style (e.g.,...
Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the Palette to drag...
Create a simple Graphical User Interface (GUI): Create new JFrameForm and use the Palette to drag and drop the Swing Containers and Controllers like the figure shown.  Your Form should accept a file name in its text field. When the user presses OK Button, the content of the String array appear in the Text area below.  Handle all Exceptions (File Not Found Exception) GUI frame
Question: Patents Apple vs Microsoft Who invented the graphical user interface (GUI)? Investigate this case, share...
Question: Patents Apple vs Microsoft Who invented the graphical user interface (GUI)? Investigate this case, share the positions argued on both sides, the law(s) at issue, the ultimate outcome and conclude with your personal analysis of the court's ruling / outcome. Also, be sure to discuss the historical impact of case/scandal on society. Include citation quotes.
In C, build a connect 4 game with no graphical use interface. Build only the text...
In C, build a connect 4 game with no graphical use interface. Build only the text interface. Use a 2D array as the Data structure. The skeleton of the game is provided for you, Build the game based on the guidelines below. The game does NOT need a mode where you play against the computer. It is simply a game of Connect 4 between player 1 and player 2. SKELETON: #include // Initializing constants #define NAME_LENGTH 30 #define BOARD_WIDTH 6...
Write the program in Java (with a graphical user interface) and have it calculate and display...
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. You need to include Calculate, Reset, and Exit buttons on your GUI. Please insert comments in the program to document the program. Allow the user to enter...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades...
The purpose of this problem is to use graphic user interface (GUI) to interactively store grades in a text file, rather than adding them manually to a script. Follow these steps to complete the program: Step 1. Use a question dialog box and ask the user “Do you want to run this Program?” with two options for “yes” and “no”. If the user’s answer is “yes”, go to the next step, otherwise, go to Step 6. Step 2. Create a...
Use the below info to create a java program A GUI interface to ensure a user...
Use the below info to create a java program A GUI interface to ensure a user is old enough to play a game. Properly formatted prompts to input name, address, phone number, and age. Remember that name, address, phone number, etc. can be broken out in additional fields. Refer to the tutorial from this week’s Reading Assignment Multiple vs. Single Field Capture for Phone Number Form Input for help with this. Instructions to ensure that the information is displayed back...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
The operating system offers a graphical vs command line user interface to interact with an electronic...
The operating system offers a graphical vs command line user interface to interact with an electronic device. Compare the graphical user interface and the command line interface in terms of speed, remote access, resource utilization, multitasking, and control.
The operating system offers a graphical vs command line user interface to interact with an electronic...
The operating system offers a graphical vs command line user interface to interact with an electronic device. Compare the graphical user interface and the command line interface in terms of speed, remote access, resource utilization, multitasking, and control. [5 Marks]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT