Azzera filtri
Azzera filtri

Generating a circular array by shifting their elements????????????

1 visualizzazione (ultimi 30 giorni)
Hi all,
I want to generate an array by shifting bits until the last element takes the value '1' such that:
1 0 0 0 0 1 1 0 0 0
0 1 0 0 0 0 1 1 0 0
0 0 1 0 0 or 0 0 1 1 0
0 0 0 1 0 0 0 0 1 1
0 0 0 0 1
How can I do that? Thanks

Risposta accettata

Image Analyst
Image Analyst il 11 Mag 2013
Someone will probably give you a cryptic one-liner using kron or some other weird function, but did you try the brute force approach?
rowVector = [1, 0, 1, 0, 0, 0]
lastOneLocation = find(rowVector, 1, 'last')
len = length(rowVector)
needToShift = len - lastOneLocation
array2D = zeros(needToShift+1, len);
array2D(1,:) = rowVector;
for row = 2: needToShift+1
array2D(row, row:end) = rowVector(1:len-row+1);
end
% Print to command window:
array2D

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by