how to creat this transformation?

1 回表示 (過去 30 日間)
benghenia aek
benghenia aek 2019 年 2 月 2 日
回答済み: madhan ravi 2019 年 2 月 2 日
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]

回答 (1 件)

madhan ravi
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{:}]

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by