i'm writing an app to read data from excel file and plot the data with matlab app designer, is there any example i can refer to

41 views (last 30 days)
i need to create a gui where the user can select an excel file with selected path and create plots with with various columns as x and y axes, i also need to provide with an dropdown menu for headings in column, is there any example cases that i can refer to?

Answers (2)

Kojiro Saito
Kojiro Saito on 4 Dec 2018
Edited: Kojiro Saito on 5 Dec 2018
It's not Excel file, but MATLAB document has an Example of uigetfile and dropdown menu.
You can also open this example by the following command.
openExample('matlab/AppdImageHistogramsExample')
If you want to specify file extensions with .xlsx and read it as a table, the following will work.
[file, path] = uigetfile('*.xlsx');
t = readtable(fullfile(path, file));
UPDATED
I've attached a sample mlapp file (as a zip file) which sets drop down menu from input Excel file.
2018125213718.jpg
  7 Comments
Laurenz Grigat
Laurenz Grigat on 8 Jun 2020
Hi Kojiro,
can you make the code behind your zip file available please? I have a very similar task and want to get some inspiration. Thanks a lot!
Kojiro Saito
Kojiro Saito on 9 Jun 2020
Hi Laurenz,
Here is a full code of the mlapp file which I had attached previously.
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
UIAxes matlab.ui.control.UIAxes
yDropDownLabel matlab.ui.control.Label
yDropDown matlab.ui.control.DropDown
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 = 'UI Figure';
% Create ReadExcelButton
app.ReadExcelButton = uibutton(app.UIFigure, 'push');
app.ReadExcelButton.ButtonPushedFcn = createCallbackFcn(app, @ReadExcelButtonPushed, true);
app.ReadExcelButton.Position = [271 427 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 287 302 108];
% Create xDropDownLabel
app.xDropDownLabel = uilabel(app.UIFigure);
app.xDropDownLabel.HorizontalAlignment = 'right';
app.xDropDownLabel.Position = [184 230 25 22];
app.xDropDownLabel.Text = 'x';
% Create xDropDown
app.xDropDown = uidropdown(app.UIFigure);
app.xDropDown.Items = {};
app.xDropDown.ValueChangedFcn = createCallbackFcn(app, @xDropDownValueChanged, true);
app.xDropDown.Position = [224 230 100 22];
app.xDropDown.Value = {};
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [170 32 300 185];
% Create yDropDownLabel
app.yDropDownLabel = uilabel(app.UIFigure);
app.yDropDownLabel.HorizontalAlignment = 'right';
app.yDropDownLabel.Position = [410 230 25 22];
app.yDropDownLabel.Text = 'y';
% Create yDropDown
app.yDropDown = uidropdown(app.UIFigure);
app.yDropDown.Items = {};
app.yDropDown.ValueChangedFcn = createCallbackFcn(app, @yDropDownValueChanged, true);
app.yDropDown.Position = [450 230 100 22];
app.yDropDown.Value = {};
% 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

Sign in to comment.


mohanambal saminathan
mohanambal saminathan on 21 Apr 2021
how to read 12 excel sheets in drop down matlab app designer

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!