How can I do linear indexing in matlab?
Show older comments
hi, Suppose I have a matrix A=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]; I want to transfer it into a linear matrix as A=[1 2 5 6 3 4 7 8 9 10 13 14 11 12 15 16]; (i.e. mortan scan order in image processing). Can you help me. All my work will start after this only. I would be very greatful to you
Accepted Answer
More Answers (4)
Abdulrazzaq
on 1 Mar 2014
Edited: Abdulrazzaq
on 1 Mar 2014
try:
B = A(:)';
Best wishes
Abdulrazzaq
dpb
on 1 Mar 2014
One way amongst many --
B=reshape(reshape(A.',2,[]),1,[]);
Consider how Matlab storage is in column-major order and what operation one needs to get to the desired organization from the original...
B=cellfun(@(c) c(:).', mat2tiles(A.',[2,2]),'uni',0);
B=[B{:}]
Roger Stafford
on 1 Mar 2014
0 votes
If you convert each of the integers 0:15 to binary, permute the digits appropriately, recalculate the numbers from these permuted digits, and finally add 1 to each, you will get the correct linear indexing. The same holds true for larger Z-orders.
Categories
Find more on Matrix Indexing 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!