Identifying blocks of data from a cell array having the same header
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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]
Risposte (1)
Guillaume
il 29 Mag 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;
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!