App Designer Drop Down to load excel data

9 vues (au cours des 30 derniers jours)
Mitchell Kemppainen
Mitchell Kemppainen le 27 Jan 2021
I have an excel sheet which has the first colum being a name, each colum after has numerical data accociated with each name (Name and date acociated with name have ther own row). I would like to use a drop down to select the name from the excel document which would in turn pull in all the data asociated with that name. The list of names from the drop down also needs to be pulled from the first colum in the excel document since it is a living document.
  2 commentaires
Mario Malic
Mario Malic le 28 Jan 2021
Hello,
This is highly reliant on how your Excel data is structured. Is there a pattern where the data associated with the person is located?
Mitchell Kemppainen
Mitchell Kemppainen le 28 Jan 2021
Hopefully this helps with how I am formatting the excel document. And this is what i have for code now.
% Button pushed function: LoadDataButton
function LoadDataButtonPushed(app, event)
clc
%%%%%%%%%% Loading Vehical Data %%%%%%%%%%
Vehical_Data=readtable('Brakes_Calculator.xlsx');
%%%%%%%%%% Loading Vehical Names %%%%%%%%%%
Name=cellstr((table2array(unique(Vehical_Data(:,1)))));
%%%%%%%%%% Loading LVW Data %%%%%%%%%%
LVW=Vehical_Data(:,2);
LVW_RAW=Vehical_Data(:,3);
LVW_CG_Z=Vehical_Data(:,4);
LVW_CG_X=Vehical_Data(:,5);
%%%%%%%%%% Loading GVW Data %%%%%%%%%%
GVW=Vehical_Data(:,7);
GVW_RAW=Vehical_Data(:,8);
GVW_CG_Z=Vehical_Data(:,9);
GVW_CG_X=Vehical_Data(:,10);
%%%%%%%%%% Loading 'Wheel" Data %%%%%%%%%%
WB=Vehical_Data(:,12);
FWD=Vehical_Data(:,13);
RWD=Vehical_Data(:,14);
%%%%%%%%%% Loading Brakes Data %%%%%%%%%%
FPD1=Vehical_Data(:,1);
FPD2=Vehical_Data(:,16);
RPD1=Vehical_Data(:,17);
RPD2=Vehical_Data(:,18);
FRD=Vehical_Data(:,19);
RRD=Vehical_Data(:,20);
HMC_Bore=Vehical_Data(:,21);
FMC_Bore=Vehical_Data(:,22);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
app.VehicalDropDown.Items=Name;
% app.VehicalDropDown.ItemsData=1:500;
% Locations=app.VehicalDropDown.ItemsData;

Connectez-vous pour commenter.

Réponses (1)

Mario Malic
Mario Malic le 28 Jan 2021
If you use readtable on your file, you'll get a nice table already prepared with the data. After you import, check if your numbers are actually imported as numbers.
t = readtable('filename.xlsx');
app.DropDownMenu.Items = t{:,1};
app.DropDownMenu.ItemsData = 1:length(app.DropDownMenu.Items);
When you set the ItemsData property this way, the number will be present in the Value property, and you can use it to index into particular rows of the table.
selectedRow = app.DropDownMenu.Value;

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by