how to creat this transformation?

1 Ansicht (letzte 30 Tage)
benghenia aek
benghenia aek am 2 Feb. 2019
Beantwortet: madhan ravi am 2 Feb. 2019
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]

Antworten (1)

madhan ravi
madhan ravi am 2 Feb. 2019
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{:}]

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by