MATLAB Answers

Finding columns that contains a specified string

4 views (last 30 days)
Ali N
Ali N on 7 Jan 2020
Answered: Guillaume on 7 Jan 2020
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

Sign in to comment.

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)

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.