rearranging in a matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, i got a question.
i got a code that eventually produces matrices like these:
x = [1 1 0 0 ];
with a n number of 1's in front followed by k number of 0's.
now im trying to rearrange it to:
x2 = [1 0 1 0]
or another example:
x = [1 1 1 1 0 0 0]
to
x2 = [1 0 1 0 1 0 1]
i hope you get the gist.
sorry if it's a bit vague, my first time posting here!
0 Kommentare
Antworten (1)
Star Strider
am 17 Sep. 2021
One approach —
x = [1 1 0 0 ];
xr = reshape(buffer(x,nnz(x)).', 1, []);
xr = xr(1:numel(x))
x = [1 1 1 1 0 0 0];
xr = reshape(buffer(x,nnz(x)).', 1, []);
xr = xr(1:numel(x))
Experiment to get different results.
.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!