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

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]
*In JAVA and JavaFX please!! CSE1322 – Assignment 8 – GUI General User Interface Assignment 8...
*In JAVA and JavaFX please!! CSE1322 – Assignment 8 – GUI General User Interface Assignment 8 Objectives • Build a GUI application similar to a calculator. • Create an application that acts as a simple calculator. Create buttons for 0-9 and a text field that displays the concatenation of the current digits as they are clicked. • Add buttons for operators “+”, “-“, “*”, and “/”. • Add a final button for “=” that calculates the computed value with the...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
Using tkinter, create a GUI interface which accepts input of annual income. Using the table below,...
Using tkinter, create a GUI interface which accepts input of annual income. Using the table below, determine and output the income tax for that income. Tax Rate Income 10% $0 to $9,875.00;  12% $9,876.01 to $40,125.00; 22% $40,126 to $85,525.00; 24% $85,526.01 to $163,300.00. Test with the following income data: 163,300.00 9,876.01 85,525.00
Using MatLab Write a program which will: a. Accept two numbers from the user m and...
Using MatLab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Accept from the user two row numbers. Multiply the two rows (element by element) and find the sum. Print the result. d. Accept from the user two column numbers. Add the two columns (element by element) and find the sum....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT