help creating array from binary code
1 次查看(过去 30 天)
显示 更早的评论
I have this sequence with your right numbering indicating the order.
0 (1) 0 (2) 0 (3) 1 (4) 1 (5) 0 (6) 0 (7) 0 (8) 0 (9) 0 (10) 1 (11) 0 (12) 0 (13) 0 (14) 0 (15)
1 (16) 0 (17) 0 (18) 1 (19) 1 (20).
As would be the code to create the following matrix?
0 (18) 1 (19) 1 (20)
0 (15) 0 (17) 1 (19)
0 (12) 0 (15) 0 (18)
0 (9) 0 (13) 0 (17)
0 (6) 1 (11) 1 (16)
0 (3) 0 (9) 0 (15)
0 个评论
回答(1 个)
Image Analyst
2013-9-25
编辑:Image Analyst
2013-9-25
out = zeros(6,3); % Initialize
% First column
out(:,1) = inputMatrix(18:-3:3,1);
% Second column
out(:,2) = inputMatrix(19:-2:9, 2);
% Third column
out(:,3) = inputMatrix(20:-1:15, 3);
It would be easy to generalize this for different sized input matrix, but you haven't said you need to do that (plus it's easy enough for you to figure out yourself).
3 个评论
Image Analyst
2013-9-25
编辑:Image Analyst
2013-9-25
Like I said, it's really easy so I'm pretty sure you can do it. This may help:
L = length(inputMatrix);
out(:,1) = inputMatrix(L-2:-3:1,1);
See if you can get the rest. I can't really do it for you because you didn't say what's constant in the output matrix - the number of rows or the number of columns, or if both vary, how you decide on the number of rows and columns.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!