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

1 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2013-5-11
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by