HELP WITH ESTRACT SUBSTRING OF STRING
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Walter Roberson
2013-12-11
regexp(String, '(?<=[34]).*?[34]', 'match')
Or so I figure as I drift off to sleep.
0 个评论
Andrei Bobrov
2013-12-11
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 个评论
Jos (10584)
2013-12-11
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!