Finding columns that contains a specified string
74 views (last 30 days)
Show older comments
Hello there
I have a large Excel file with multiple headers that I attached. I want to know how I can find a specific column. For example "Shoe via sloe" from the first header and "L GRF" from the third header. Then I want to copy all matched columns numbers in another array. Using this I want to find specific columns for further analysis.
Regards,
0 Comments
Accepted Answer
Guillaume
on 7 Jan 2020
The format of your excel file is really not ideal. Anyway, this is one way:
header = readcell('Rahmani.xlsx', 'Range', '1:4'); %read 1st four rows as a cell array of char vectors. Matlab automatically discard the first column since it's empty for the header
data = readmatrix('Rahmani.xlsx'); %read numerical part
data = data(:, 2:end); %discard first column to match header
selectedcolumns = contains(header(1, :), 'Shoes via Sole') & strcmp(header(2, :), 'L GRF'); %Search text HAS to be spelled correctly!
selecteddata = data(:, selectedcolumns)
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!