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

arraycircularshift

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

Best Answer

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