Extract headers from CSV and add to app.Items

I would like to take the first row of a csv file (headers) and add those to a dropdown menu item. I tried something like this:
bud_serials = readtable(annotation);
header = bud_serials(1:1, :)
app.SelectTestID.Items = {header};
I get an error: "'Items' must be a 1-D cell array of character vectors or a string array."

 Accepted Answer

header = bud_serials.Properties.VariableNames;
app.SelectTestID.Items = header;

4 Comments

LabRat
LabRat on 25 Jul 2022
Edited: LabRat on 25 Jul 2022
Thank you Walter! Will you please kindly guide on how to remove the first column header? For example if the above code provides headers in cell locations A1 to D1, how would I extract just B1 to D1 in the drop down menu?
app.SelectTestID.Items = header(2:4);
Is there a way to automatically take as many header columns as is available? Each csv file will have a different number of header columns.
app.SelectTestID.Items = header(2:end);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!