Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Saeid
Saeid el 28 de Mayo de 2019
Comentada: Saeid el 29 de Mayo de 2019
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]

Respuestas (1)

Guillaume
Guillaume el 29 de Mayo de 2019
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;

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by