All Possible combinations of rows

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.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 18 Mar 2016
Modifié(e) : Azzi Abdelmalek le 18 Mar 2016
[ii,jj]=meshgrid((1:s1),(1:s2));
v=[ jj(:) ii(:) ones(s1*s2,1)]';

Community Treasure Hunt

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

Start Hunting!

Translated by