All Possible combinations of rows

2 次查看(过去 30 天)
I am trying to make a vector matrix where each column represents all possible points in an image. Here is what I want to do
s1=2160;
s2=3600;
count=1;
for i=1:s1
for j=1:s2
vector(:,count)=[j;i;1];
count=count+1;
end
end
but in a much faster way using vectorization. How do I do that ? This simple code takes about 40 seconds to run on my PC.

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-3-18
编辑:Azzi Abdelmalek 2016-3-18
[ii,jj]=meshgrid((1:s1),(1:s2));
v=[ jj(:) ii(:) ones(s1*s2,1)]';

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by