How do I split a string of numbers in n+1th successive intervals and put them in a array or matrix.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Meg Cullen
le 30 Avr 2019
Réponse apportée : Star Strider
le 30 Avr 2019
I need to split a string of numbers, for example-
123456123456123456123.....
into separate elements in the form
12345612
23456123
34561234
45612345
56123456
61234561
.....
and so on.....where the next element starts from the n+1th number in the string and size remains same.
0 commentaires
Réponse acceptée
Star Strider
le 30 Avr 2019
Another option is to use a loop:
n = '123456123456123456123'; % Convert To Character Array
len = 8; % Length Of Segments
for k = 1:numel(n)-len+1
s(k,:) = n(k:k+len-1); % Character Array
sn(k,:) = str2double(s(k,:)); % Numeric Array
end
Experiment to get the result you want.
0 commentaires
Plus de réponses (1)
Stephen23
le 30 Avr 2019
>> S = '123456123456123456123';
>> [C,T] = regexp(S,'(\d)\d{0,6}','match','tokens');
>> D = strcat(C(:),vertcat(T{2:end},{''}));
>> D{:}
ans =
12345612
ans =
23456123
ans =
3456123
0 commentaires
Voir également
Catégories
En savoir plus sur String 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!