how to creat this transformation?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi every one, I have a vector A. All values of vector A are either zeros or 1 numbers
A=[0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0]
How to convert half of each segment of 1 in to 0 in order to obtein vector B
B=[0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0]
댓글 수: 0
답변 (1개)
madhan ravi
2019년 2월 2일
B=A;
index=find(A);
idx=find(diff(index)~=1);
b=[idx(1) diff(idx) numel(index)-idx(end)];
R=mat2cell(A(index),1,b);
C=cellfun(@(x)[ones(1,fix(numel(x)/2)) ...
zeros(1,numel(x)-fix(numel(x)/2))],R,'un',0);
z=mat2cell(index,1,b);
B([z{:}])=[C{:}]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!