I have a problem since the beginning of this month. It looks very simple but I can't program this into Matlab.
I have a matrix of variable length which consists of zeros and ones
x=[1;0;1;0;1;1;1;1;1;1;0;0;0;0;0;1;1;1;1;1;1;1;0;0;0;0;0;1;1;0]
I have to come up with a new matrix which counts consecutive ones.
x=[1;0;1;0;0;0;0;0;0;6;0;0;0;0;0;0;0;0;0;0;0;7;0;0;0;0;0;0;2;0]
The problem is that the lentgh of the consecutive ones can vary.
I've already tried with this code but it does not work. Can someon help me please?
count=zeros;for i=20 if x(i,1)>0 count(i,1)=count+1; elseif x(i,1)<1 count(i,1)=0; endend
Best Answer