Generating a circular array by shifting their elements????????????
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time 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!