All Possible combinations of rows

2 Ansichten (letzte 30 Tage)
Guneet Singh Mehta
Guneet Singh Mehta am 18 Mär. 2016
Bearbeitet: Walter Roberson am 19 Mär. 2016
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.

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 18 Mär. 2016
Bearbeitet: Azzi Abdelmalek am 18 Mär. 2016
[ii,jj]=meshgrid((1:s1),(1:s2));
v=[ jj(:) ii(:) ones(s1*s2,1)]';

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by