App Designer Drop Down to load excel data

조회 수: 9 (최근 30일)
Mitchell Kemppainen
Mitchell Kemppainen 2021년 1월 27일
답변: Mario Malic 2021년 1월 28일
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
Mario Malic
Mario Malic 2021년 1월 28일
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 2021년 1월 28일
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;

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

답변 (1개)

Mario Malic
Mario Malic 2021년 1월 28일
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;

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by