Finding columns that contains a specified string

74 views (last 30 days)
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,

Accepted Answer

Guillaume
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)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!