develop a app with appdesigner to plot multiple graph from excel sheet

3 views (last 30 days)
i had created a app through app designer ,which import and read data from excel and shos it in uitable now i have put two dropdown meny one for x and one for y and the user selects the column name to plot accordingly ,now i have to modify the code so that i can select multiplecolumn names from dropdown menu so that multiple graph would come according to user selection .
below is my code which i have written ,plzz help me modify it
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
readexcelButton matlab.ui.control.Button
UITable matlab.ui.control.Table
xDropDownLabel matlab.ui.control.Label
xDropDown matlab.ui.control.DropDown
yDropDownLabel matlab.ui.control.Label
yDropDown matlab.ui.control.DropDown
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: readexcelButton
function readexcelButtonPushed(app, event)
[file, path] = uigetfile('*.xlsx');
if isequal(file,0)
msgbox('Please input an Excel file')
else
t = readtable(fullfile(path, file));
app.UITable.Data = t;
% Set column names as a pull down menu
app.xDropDown.Items = t.Properties.VariableNames;
app.yDropDown.Items = t.Properties.VariableNames;
plot(app.UIAxes, app.UITable.Data.(app.xDropDown.Value), app.UITable.Data.(app.yDropDown.Value));
end
end
% Value changed function: xDropDown
function xDropDownValueChanged(app, event)
value = app.xDropDown.Value;
plot(app.UIAxes, app.UITable.Data.(app.xDropDown.Value), app.UITable.Data.(app.yDropDown.Value));
end
% Value changed function: yDropDown
function yDropDownValueChanged(app, event)
value = app.yDropDown.Value;
plot(app.UIAxes, app.UITable.Data.(app.xDropDown.Value), app.UITable.Data.(app.yDropDown.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 readexcelButton
app.readexcelButton = uibutton(app.UIFigure, 'push');
app.readexcelButton.ButtonPushedFcn = createCallbackFcn(app, @readexcelButtonPushed, true);
app.readexcelButton.Position = [271 445 100 22];
app.readexcelButton.Text = 'read excel';
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'Column 1'; 'Column 2'; 'Column 3'; 'Column 4'};
app.UITable.RowName = {};
app.UITable.Position = [170 378 302 50];
% Create xDropDownLabel
app.xDropDownLabel = uilabel(app.UIFigure);
app.xDropDownLabel.HorizontalAlignment = 'right';
app.xDropDownLabel.Position = [132 330 25 22];
app.xDropDownLabel.Text = 'x';
% Create xDropDown
app.xDropDown = uidropdown(app.UIFigure);
app.xDropDown.ValueChangedFcn = createCallbackFcn(app, @xDropDownValueChanged, true);
app.xDropDown.Position = [172 330 100 22];
% Create yDropDownLabel
app.yDropDownLabel = uilabel(app.UIFigure);
app.yDropDownLabel.HorizontalAlignment = 'right';
app.yDropDownLabel.Position = [417 330 25 22];
app.yDropDownLabel.Text = 'y';
% Create yDropDown
app.yDropDown = uidropdown(app.UIFigure);
app.yDropDown.ValueChangedFcn = createCallbackFcn(app, @yDropDownValueChanged, true);
app.yDropDown.Position = [457 330 100 22];
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [30 13 581 291];
% 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 = app1
% 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

Accepted Answer

Kevin Holly
Kevin Holly on 28 Apr 2022
sanket,
Please see the app attached. Let me know if you have any more questions.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!