from here i have to count the number 1 in such way
result: 0,4,0,3,0,5…. how to get this?
Best Answer
If you have the Image Processing Toolbox, it's just two real lines of code, a call to regionprops and a line to extract the lengths from what regionprops returns.
You can use the TEXTSCAN function by specifying delimiters and then use LENGTH function to find the length of each sequence. After that, you can compute the number of occurrences with HIST function as in the example below:
%Creating a binary sequence in a string with no spaces
To do the same operation for finding run lengths and frequencies of "zeros" instead of "'ones", change the delimiter in the TEXTSCAN function to be '1' instead of '0'.
Best Answer