Making consecutive 1s and 0s as a seperate element
조회 수: 2 (최근 30일)
이전 댓글 표시
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]
댓글 수: 2
Sudhakar Shinde
2020년 10월 17일
When you create vector in matlab, two elements of vector are separated by comma (,) or space. Meaning of both are same.
채택된 답변
Ameer Hamza
2020년 10월 17일
편집: Ameer Hamza
2020년 10월 17일
You can create a cell array
a = [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);
end
Result
>> 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
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Live Scripts and Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!