The padarray function in the Images package can solve your problem or give 
you inspiration if you want to do it differently.

Den fredagen den 25:e april 2014 kl. 05:43:40 UTC+2 skrev Tomas Lycken:
>
> Given the following function definition
>
> function foo{T<:FloatingPoint}(A::Array{T})
>     B = copy(A)
>     #do some work on B
> end
>
> is there any (easy) way I can replace the call to copy() with a call that 
> allocates an array that is 2 elements longer in every dimension, and copies 
> A into the middle? A few examples might clarify what I mean:
>
> A = [1 2]    =>   B = [0 1 2 0]
> A = [1 2; 3 4]     =>    B = [0 0 0 0; 0 1 2 0; 0 3 4 0; 0 0 0 0]
>
> In two dimensions I could do the following
>
> B = similar(A, eltype(A), ([size(A)...].+2)...);
> B[2:end-1,2:end-1] = copy(A);
>
> but on the second line I'm making assumptions about the number of 
> dimensions. Is it possible to accomplish this without making that 
> assumption?
>
> // Tomas
>

Reply via email to