Simple menu selection plot dependent on radio button selection (App designer)

1 Ansicht (letzte 30 Tage)
Hello,
I am trying to design a simple app on app designer with 3 components, a UI axes, a drop down menu, and radio buttons. The drop down menu has two options to select from as a starting place, the user would then have to choose one of two options from the drop down menu in order to display the corresponding plot (total 4 plots for each case):
Plots:
1) Periodic & pretty plot (x1,y1)
2) Periodic & not pretty plot (x4,y4)
3) Non periodic & not pretty plot (x2,y2)
4) Non periodic & pretty plot ( x3,y3)
My attempt at this is to first read the table from the excel file I have, and then use switch/case statements along with if else conditions as follows:
classdef Simple_App_Test < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
BeautyDropDownLabel matlab.ui.control.Label
BeautyDropDown matlab.ui.control.DropDown
DataTypeButtonGroup matlab.ui.container.ButtonGroup
PeriodicButton matlab.ui.control.RadioButton
NonperiodicButton matlab.ui.control.RadioButton
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
dataset = readtable('App_test.xlsx');
x1 = dataset(:,1);
x2 = dataset(:,3);
x3 = dataset(:,5);
x4 = dataset(:,7);
y1 = dataset(:,2);
y2 = dataset(:,4);
y3 = dataset(:,6);
y4 = dataset(:,8);
end
% Selection changed function: DataTypeButtonGroup
function DataTypeButtonGroupSelectionChanged(app, event)
selectedButton = app.DataTypeButtonGroup.SelectedObject;
value = app.DataTypeButtonGroup.Value;
switch value
case "Periodic"
if app.BeautyDropDown.Value == 'Pretty'
plot(app.UIAxes,x1,y1);
else
plot(app.UIAxes,x4,y4);
end
case "Non periodic"
if app.BeautyDropDown.Value == 'Not Pretty'
plot(app.UIAxes,x2,y2);
else
plot(app.UIAxes,x3,y3);
end
end
end
% Value changed function: BeautyDropDown
function BeautyDropDownValueChanged(app, event)
value = app.BeautyDropDown.Value;
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 = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [90 159 450 291];
% Create BeautyDropDownLabel
app.BeautyDropDownLabel = uilabel(app.UIFigure);
app.BeautyDropDownLabel.HorizontalAlignment = 'right';
app.BeautyDropDownLabel.Position = [353 71 43 22];
app.BeautyDropDownLabel.Text = 'Beauty';
% Create BeautyDropDown
app.BeautyDropDown = uidropdown(app.UIFigure);
app.BeautyDropDown.Items = {'Pretty', 'Not Pretty'};
app.BeautyDropDown.ValueChangedFcn = createCallbackFcn(app, @BeautyDropDownValueChanged, true);
app.BeautyDropDown.Position = [411 71 100 22];
app.BeautyDropDown.Value = 'Not Pretty';
% Create DataTypeButtonGroup
app.DataTypeButtonGroup = uibuttongroup(app.UIFigure);
app.DataTypeButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @DataTypeButtonGroupSelectionChanged, true);
app.DataTypeButtonGroup.Title = 'Data Type';
app.DataTypeButtonGroup.Position = [120 29 123 106];
% Create PeriodicButton
app.PeriodicButton = uiradiobutton(app.DataTypeButtonGroup);
app.PeriodicButton.Text = 'Periodic';
app.PeriodicButton.Position = [11 60 65 22];
app.PeriodicButton.Value = true;
% Create NonperiodicButton
app.NonperiodicButton = uiradiobutton(app.DataTypeButtonGroup);
app.NonperiodicButton.Text = 'Non periodic';
app.NonperiodicButton.Position = [11 38 89 22];
% 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 = Simple_App_Test
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
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
Here is a screen shot of the design view:
I tried running the app but nothing gets plotted on the axis no matter what selection I make... I would really appreciate any guidence on this.

Antworten (0)

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by