HELP WITH ESTRACT SUBSTRING OF STRING
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
good, I wish to raise my problem, because I know how to do. I, for example have a long string as follows:
[3 -1 -1 -1 -1 -1 1 -1 -1 -1 0 -1 -1 -1 -1 4 -1 0 -1 -1 -1 0 -1 -1 3 -1 -1 -1 -1 -1 -1 4 -1 -1 0
-1 1 -1 -1 -1 0 -1 1 -1 -1 -1 -1 -1 -1 1 -1 0 -1 -1 4……..
What I want to do is the following:
1) extracting substrings so that starts for next 3/4 and ends 3/4 including the upcoming latter. For example:
[-1 -1 -1 -1 -1 1 -1 -1 -1 0 -1 -1 -1 -1 4]
Next substring;
[-1 0 -1 -1 -1 0 -1 -1 3]
Next substring;
[-1 -1 -1 -1 -1 -1 4]
And so on
0 Commenti
Risposte (3)
Walter Roberson
il 11 Dic 2013
regexp(String, '(?<=[34]).*?[34]', 'match')
Or so I figure as I drift off to sleep.
0 Commenti
Andrei Bobrov
il 11 Dic 2013
a = [3 -1 -1 -1 -1 -1 1 -1 -1 -1 0 -1 -1 -1 -1 4 -1 0 -1 -1 -1 0 -1 -1 3 -1 -1 -1 -1 -1 -1 4 -1 -1 0 -1 1 -1 -1 -1 0 -1 1 -1 -1 -1 -1 -1 -1 1 -1 0 -1 -1 4];
l = a == 3 | a== 4;
l(2:end-1) = circshift(l(2:end-1),[0 1]);
l(end) = 0;
out = accumarray(cumsum(l(:)),a(:),[],@(x){x});
2 Commenti
Jos (10584)
il 11 Dic 2013
If you have version 2013b, there is a function called strsplit , that might work on numerical arrays (like strfind used to do). I cannot test this, though.
C = strsplit(str,[3 4])
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!