How to convert 0's and 1's to intergers
Show older comments
For example i have an array of ones and zeros, 100 total.(00000,1111111111,0000000000000,11111...). How can i count them, and return integers for example (0,1,2,4,3,1,..)
10 Comments
Thomas
on 2 May 2012
what logic do you use to convert (00000,1111111111,0000000000000,11111...) to (0,1,2,4,3,1,..)?
Geoff
on 2 May 2012
I'm baffled too. You describe two different things (conversion from binary, and counting), then give an example that shows neither.
kimiri
on 2 May 2012
Walter Roberson
on 2 May 2012
What do you want done with the counts then?
You have 100 total entries, right? But you want to find the lengths of sequences of consecutive 0's and 1's? There wouldn't necessarily be 100 such sequences, so using a for loop from 1:100 would not seem appropriate.
kimiri
on 2 May 2012
per isakson
on 2 May 2012
What type of array is (000,111...). Are those ascii-characters? Double?
Geoff
on 2 May 2012
Uhhhh, do you mean you have a single stream, not a partitioned list as you described: 000001111111111000000000000011111...
And you want to mark off each low-high and high-low transition, count the values in between, and put that count into an array representing all groups?
For this data that would mean: [5,10,13,5,...]
With indices that are implicit due to the array order (and you could always subtract 1 from the 1-based index.
Richard Brown
on 2 May 2012
Can you post a concrete example of what the sequences look like and the corresponding integers that you'd want?
kimiri
on 2 May 2012
Geoff
on 2 May 2012
In the words of Hoggle from The Labyrinth.... "Well, why didn't you SAY SO?" =)
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!