Can I ask for help in making a GUI?
조회 수: 1 (최근 30일)
이전 댓글 표시
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:
"Requirements:
Create a GUI that will show demonstrate different plots in Matlab.
- 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.
- The user has the option to choose the type of graph to use in a radio button (plot, comet, stairs, stem)
- 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.
- 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.'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/215136/image.png)
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
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: ValuesofXEditField
function ValuesofXEditFieldValueChanged(app, event)
end
% Value changed function: SineCheckBox
function SineCheckBoxValueChanged(app, event)
end
% Value changed function: CosineCheckBox
function CosineCheckBoxValueChanged(app, event)
end
% Value changed function: TangentCheckBox
function TangentCheckBoxValueChanged(app, event)
end
% Value changed function: LogarithmCheckBox
function LogarithmCheckBoxValueChanged(app, event)
end
% Value changed function: ExponentialCheckBox
function ExponentialCheckBoxValueChanged(app, event)
end
% Value changed function: SquarerootCheckBox
function SquarerootCheckBoxValueChanged(app, event)
end
end
% 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';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = project_app
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
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
Andreas Bernatzky
2019년 4월 21일
you are sure you want the X-Values to be randomly generated and not the Y-Values?
X-Values makes no sense to me
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!