How do you convert linear array to 2by2 matrix?
显示 更早的评论
I have a linear and I want to create a 2 by 2 matrix for every five values but I dont want to use a for loop as it is slow. Is there a more direct way?
5 个评论
Azzi Abdelmalek
2013-6-22
Do you mean for every four values?
David Dijemeni
2013-6-22
编辑:Image Analyst
2013-6-22
Azzi Abdelmalek
2013-6-22
编辑:Azzi Abdelmalek
2013-6-22
what about 26 and 8 in your example? and 1 2 4 4 1 2 5 4 1 2 6 4 is not a 2x2 array
Azzi Abdelmalek
2013-6-22
David, can you edit your question. Give a short example and write what should be the result. If you are asking for a 2x2 array, you should show us this 2x2 array
Image Analyst
2013-6-22
编辑:Image Analyst
2013-6-22
I don't understand either. You show a 4 by 4 array. What part(s) of that are the 2 by 2 arrays? The quadrants? Please use unique numbers so we can see where each number goes - there are too many 1s, 2s, and 4s to see where each one goes to. And where does the "five" (as in "for every five values") come into play? And what does this have to do with image processing?
回答(2 个)
Azzi Abdelmalek
2013-6-22
编辑:Azzi Abdelmalek
2013-6-22
Use reshape function
%example
x=1:20
out=reshape(x,2,2,[])
Image Analyst
2013-6-22
% Create sample linear array
m = [1, 2, 3, 4]
% Create 2D array (probably the fastest way).
m2D = [m(1), m(2); m(3), m(4)]
% Alternate way
m2Da = reshape(m, [2, 2])
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!