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

조회 수: 7 (최근 30일)
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
  댓글 수: 2
Kevin Holly
Kevin Holly 2022년 4월 27일
Can you use a list box instead of a dropdown box?
sanket neharkar
sanket neharkar 2022년 4월 28일
yes i could use but i dont know to how to do with that
plzz can you help me built the code

댓글을 달려면 로그인하십시오.

채택된 답변

Kevin Holly
Kevin Holly 2022년 4월 28일
sanket,
Please see the app attached. Let me know if you have any more questions.
  댓글 수: 3
Aditya
Aditya 2024년 1월 9일
I am having two problem with my code. I want to plot the data which must be chosen from a specific (from date to date) like Jan 2 2024 to January 5 2024.
I have the data in excel sheet but i am not able to plot it .
Can someone Help me out with this.
Kevin Holly
Kevin Holly 2024년 1월 9일
Can you post a question by clicking "Ask" tab at the top of the page? Be sure to provide enough information, so that we can help you. If applicable and if you are able, please attach your code.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by