Splitting an array into variable lengths depending on it's content
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an array containing S sections of data that I need to extract and create S new arrays each containing one of those sections. The start of each section has the string 'E0=' and is followed by the data I need (though this amount varies between section). i.e. if there are N elements, strf{2} is a cell
strf{2} = [E0= 5 614 82 97 E0= 91 44 7 E0= 54 774 624 6339 4 1...]
So far I have found each element of the array where 'E0=' is using this code:
dEpres = strcmp(strf{2}, 'E0=');
S = sum(dEpres);
dEelems = find(dEpres, S);
Such that dEelems = [1 6 10 ...].
What I want to do now is split this array into n arrays at the elements where 'E=0' is so I have:
array1 = [E0= 5 614 82 97] array2 = [E0= 91 44] array3 = [E0= 54 774 624 6339 4 1]
I have tried to use some sort of for loop to generate array(i) where i=1:S but haven't been successful.
Any help would be really appreciated!
Thanks, Matt
0 commentaires
Réponses (1)
Vishal Rane
le 12 Mar 2014
If str = 'E0= 5 614 82 97 E0= 91 44 7 E0=54 774 624 6339 4 1...'
[matchstart,~,~,~,tokenstring,~,~] = regexp( str, 'E0=\s|E0=', 'split')
matchstart =
'' '5 614 82 97 ' '91 44 7 ' '54 774 624 6339 4 1...'
tokenstring =
'E0= ' 'E0= ' 'E0='
matchstart(1) = []
cellfun(@horzcat, tokenstring, matchstart, 'un', 0)
ans =
'E0= 5 614 82 97 ' 'E0= 91 44 7 ' 'E0=54 774 624 6339 4 1...'
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!