Finding columns that contains a specified string

14 visualizaciones (últimos 30 días)
Ali N
Ali N el 7 de En. de 2020
Respondida: Guillaume el 7 de En. de 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,

Respuesta aceptada

Guillaume
Guillaume el 7 de En. de 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)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by