Finding columns that contains a specified string

조회 수: 14 (최근 30일)
Ali N
Ali N 2020년 1월 7일
답변: Guillaume 2020년 1월 7일
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,

채택된 답변

Guillaume
Guillaume 2020년 1월 7일
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개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by