Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 11 May 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

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!