Hi Steven,

Thanks for your answer but my question is a bit different.
I'm not asking about creating a mesh grid and how or why doing it. 
My question is more "naive": 
Why the first method is faster than the 2 with only (well written) 1 line 
command.

and a more general question is: why "repeat" is slower than "repmat"   , 
for example: 

*tic(); repmat([1:10],1000,1000); toc()*

elapsed time: 0.035878247 seconds


*tic(); **repeat([1:10],outer=[1000,1000]);** toc()*

elapsed time: 1.176858309 seconds

Thanks


Le vendredi 27 février 2015 15:11:10 UTC+1, antony schutz a écrit :
>
> Hello, 
>
> I have a question about the best way to implement a grid similar to a mesh 
> grid: 
> My first intuition was to do the following: 
>
> nx = 256
> nb = 195
>
> kx = [-nx/2:-1+nx/2]
>
> tic()
> k1   = repmat(kx,1,nx)
> k1v = vec(k1)'#/nx
> k1m = repmat(k1v,nb,1)
> toc()
> # 0.0256 sec 
>
> Then I tried in one operation the following: 
> tic()
> ka = repeat(kx,outer=[nx,nb])'# reshape( 
> repeat(repeat(kx,inner=[nb]),outer=[nx]) ,nb,nx*nx )
> toc()
> # 0.477
>
> Does somebody knows why the repeat is ~20 times slower than the 
> repeat/vec/repmat 
> Is it the best way to do this ?
>
> Thanks in advance
>
> Bests.
>
> Antony
>
>

Reply via email to