How do I organize data when number of data points is unknown?

So I have a bunch of data that looks like this,
1111111111111112222222222222333333444444444555511111111222222333..etc this is just an example. I don't know how many digits there are for each number, and sometimes the sequence goes up to 234 and sometimes to 43, it's random. What I want to do is take this data and have each string of the same digit (11111) become one digit (1) and continue from 1 all the way to the end, not start over at one again. I'm sorry if this is hard to understand, but I'm not sure how to go about this. Any help is appreciated. Thanks

1 件のコメント

Chad Gilbert
Chad Gilbert 2013 年 7 月 3 日
Could you give an example of the desired output? Also, is your input a string or a numeric array?

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2013 年 7 月 3 日

0 投票

This code
str = '1111111111111112222222222222333333444444444555511111111222222333';
str([ true, not( diff( double( str ) ) == 0 ) ])
returns
ans =
12345123
string in and string out

その他の回答 (1 件)

Jan
Jan 2013 年 7 月 3 日
編集済み: Jan 2013 年 7 月 3 日

2 投票

The FEX submission RunLength contains fast C-Mex code and M-code also to solve this. The 2nd output can be ignored, because you do not need the number of occurrences.
Another method:
str = '1111111111111112222222222222333333444444444555511111111222222333';
pad = [str, '*'];
result = str(pad(1:end-1) ~= pad(2:end));

カテゴリ

ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by