Can I ask for help in making a GUI?

4 views (last 30 days)
Dave Rafael Dador Diez
Dave Rafael Dador Diez on 21 Apr 2019
Edited: per isakson on 21 Apr 2019
Hey there fellow Matlab users!
I'm quite new in the world of Matlab and I request for your help. Our professor is asking us to make a GUI for creating a graph.
Here is the project overview:
Create a GUI that will show demonstrate different plots in Matlab.
  1. The user will be asked for the values of x separated by commas in a textbox. If the user does not want to enter the x values, he can alternatively click a button to generate 100 random x double values from 1 to 100. The x values should be displayed in text once the “Graph” button has been clicked.
  2. The user has the option to choose the type of graph to use in a radio button (plot, comet, stairs, stem)
  3. The user has the option to choose the functions for which x would be evaluated in a checkbox (sin, cos, tan, exp, log, sqrt). If more than one function is checked, make sure that they all appear in a single figure using hold. The y values for each function selected should also be displayed in text once the “Graph” button has been clicked.
  4. A button named “Graph” is available to start plotting the x values against the y values. Make sure that the resulting graph has appropriate title, labels and design. You are free to set any properties as you wish.'
classdef project_app < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TypeofgraphButtonGroup matlab.ui.container.ButtonGroup
PlotButton matlab.ui.control.RadioButton
CometButton matlab.ui.control.RadioButton
StemButton matlab.ui.control.RadioButton
StepButton matlab.ui.control.RadioButton
ValuesofXEditFieldLabel matlab.ui.control.Label
ValuesofXEditField matlab.ui.control.NumericEditField
FunctionsofXButtonGroup matlab.ui.container.ButtonGroup
SineCheckBox matlab.ui.control.CheckBox
CosineCheckBox matlab.ui.control.CheckBox
TangentCheckBox matlab.ui.control.CheckBox
LogarithmCheckBox matlab.ui.control.CheckBox
ExponentialCheckBox matlab.ui.control.CheckBox
SquarerootCheckBox matlab.ui.control.CheckBox
UIAxes matlab.ui.control.UIAxes
% Callbacks that handle component events
methods (Access = private)
% Value changed function: ValuesofXEditField
function ValuesofXEditFieldValueChanged(app, event)
% Value changed function: SineCheckBox
function SineCheckBoxValueChanged(app, event)
% Value changed function: CosineCheckBox
function CosineCheckBoxValueChanged(app, event)
% Value changed function: TangentCheckBox
function TangentCheckBoxValueChanged(app, event)
% Value changed function: LogarithmCheckBox
function LogarithmCheckBoxValueChanged(app, event)
% Value changed function: ExponentialCheckBox
function ExponentialCheckBoxValueChanged(app, event)
% Value changed function: SquarerootCheckBox
function SquarerootCheckBoxValueChanged(app, event)
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create TypeofgraphButtonGroup
app.TypeofgraphButtonGroup = uibuttongroup(app.UIFigure);
app.TypeofgraphButtonGroup.TitlePosition = 'centertop';
app.TypeofgraphButtonGroup.Title = 'Type of graph ';
app.TypeofgraphButtonGroup.Position = [51 222 112 113];
% Create PlotButton
app.PlotButton = uiradiobutton(app.TypeofgraphButtonGroup);
app.PlotButton.Text = 'Plot';
app.PlotButton.Position = [11 67 43 22];
app.PlotButton.Value = true;
% Create CometButton
app.CometButton = uiradiobutton(app.TypeofgraphButtonGroup);
app.CometButton.Text = 'Comet';
app.CometButton.Position = [11 45 58 22];
% Create StemButton
app.StemButton = uiradiobutton(app.TypeofgraphButtonGroup);
app.StemButton.Text = 'Stem';
app.StemButton.Position = [11 23 50 22];
% Create StepButton
app.StepButton = uiradiobutton(app.TypeofgraphButtonGroup);
app.StepButton.Text = 'Step';
app.StepButton.Position = [11 2 47 22];
% Create ValuesofXEditFieldLabel
app.ValuesofXEditFieldLabel = uilabel(app.UIFigure);
app.ValuesofXEditFieldLabel.HorizontalAlignment = 'right';
app.ValuesofXEditFieldLabel.Position = [17 361 65 22];
app.ValuesofXEditFieldLabel.Text = 'Values of X';
% Create ValuesofXEditField
app.ValuesofXEditField = uieditfield(app.UIFigure, 'numeric');
app.ValuesofXEditField.ValueChangedFcn = createCallbackFcn(app, @ValuesofXEditFieldValueChanged, true);
app.ValuesofXEditField.Position = [97 361 100 22];
% Create FunctionsofXButtonGroup
app.FunctionsofXButtonGroup = uibuttongroup(app.UIFigure);
app.FunctionsofXButtonGroup.TitlePosition = 'centertop';
app.FunctionsofXButtonGroup.Title = 'Functions of X';
app.FunctionsofXButtonGroup.Position = [46 31 123 167];
% Create SineCheckBox
app.SineCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.SineCheckBox.ValueChangedFcn = createCallbackFcn(app, @SineCheckBoxValueChanged, true);
app.SineCheckBox.Text = 'Sine';
app.SineCheckBox.Position = [20 122 46 22];
% Create CosineCheckBox
app.CosineCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.CosineCheckBox.ValueChangedFcn = createCallbackFcn(app, @CosineCheckBoxValueChanged, true);
app.CosineCheckBox.Text = 'Cosine';
app.CosineCheckBox.Position = [20 101 59 22];
% Create TangentCheckBox
app.TangentCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.TangentCheckBox.ValueChangedFcn = createCallbackFcn(app, @TangentCheckBoxValueChanged, true);
app.TangentCheckBox.Text = 'Tangent';
app.TangentCheckBox.Position = [20 80 64 22];
% Create LogarithmCheckBox
app.LogarithmCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.LogarithmCheckBox.ValueChangedFcn = createCallbackFcn(app, @LogarithmCheckBoxValueChanged, true);
app.LogarithmCheckBox.Text = 'Logarithm';
app.LogarithmCheckBox.Position = [20 59 76 22];
% Create ExponentialCheckBox
app.ExponentialCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.ExponentialCheckBox.ValueChangedFcn = createCallbackFcn(app, @ExponentialCheckBoxValueChanged, true);
app.ExponentialCheckBox.Text = 'Exponential';
app.ExponentialCheckBox.Position = [20 38 85 22];
% Create SquarerootCheckBox
app.SquarerootCheckBox = uicheckbox(app.FunctionsofXButtonGroup);
app.SquarerootCheckBox.ValueChangedFcn = createCallbackFcn(app, @SquarerootCheckBoxValueChanged, true);
app.SquarerootCheckBox.Text = 'Square root';
app.SquarerootCheckBox.Position = [20 17 85 22];
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [196 10 432 352];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
% App creation and deletion
methods (Access = public)
% Construct app
function app = project_app
% Create UIFigure and components
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
This is the code from making the GUI. I'm not even close to average nor are my groupmates and I feel really pathetic about that. So please, if there is anyone out there who can spare their time to help, please do. I only have two days for this project and I would gladly love a hand. Thank you so much again. I would also like to be able to call you if it's alright with you as I have too many questions that can't be asked by simple text.
  1 Comment
Andreas Bernatzky
Andreas Bernatzky on 21 Apr 2019
you are sure you want the X-Values to be randomly generated and not the Y-Values?
X-Values makes no sense to me

Sign in to comment.

Answers (1)

Andreas Bernatzky
Andreas Bernatzky on 21 Apr 2019
Look at the attachements. Should do the work

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by