필터 지우기
필터 지우기

Identifying blocks of data from a cell array having the same header

조회 수: 1 (최근 30일)
Saeid
Saeid 2019년 5월 28일
댓글: Saeid 2019년 5월 29일
I usually use xlsread to load large excel datasheets for further manipulation. The excel worksheet looks somewhat like this:
Sometimes I need to isolate all the columns that have the same header, i.e., in the above case I need to separate all columns under the Orange, Red and Green headers, and create new arrays from those. Is it possible to have an array just composed of the headers, and maybe another array giving the starting and the ending number of the columns? The Output should be something like:
HeaderArray= {'Day 12' 'Night 24' 'Morning 3'}
HeaderStart=[1 5 11]
HeaderEnd=[4 10 13]

답변 (1개)

Guillaume
Guillaume 2019년 5월 29일
Assuming that the runs of identical headers are always continuous
header = repelem({'Day 12', 'Night 24', 'Morning 3'}, [4, 6, 3]); %construct demo data
[HeaderArray, ~, id] = unique(header, 'stable');
locs = find(diff([0; id; 0]) ~= 0);
HeaderStart = locs(1:end-1);
HeaderEnd = locs(2:end) - 1;

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by