Identifying blocks of data from a cell array having the same header
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I usually use xlsread to load large excel datasheets for further manipulation. The excel worksheet looks somewhat like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/221577/image.png)
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 comentario
Respuestas (1)
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;
Ver también
Categorías
Más información sobre Database Toolbox 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!