MATLAB: Making consecutive 1s and 0s as a seperate element ansrak If I have a cell say a= [1 0 0 0 1 1 1 1 0 1] I want b= [ 1,0 0 0, 1 1 1 1,0,1] Best Answer You can create a cell arraya = [1 1 0 0 0 1 1 1 1 0 1 1];idx = [1 find(diff(a)~=0)+1 numel(a)+1];C = cell(numel(idx)-1, 1);for i = 1:numel(C) C{i} = a(idx(i):idx(i+1)-1);endResult>> C{1}ans = 1 1>> C{2}ans = 0 0 0>> C{3}ans = 1 1 1 1>> C{4}ans = 0>> C{5}ans = 1 1
Best Answer