How to make this "for loop"

Hi. I made a function in Matlab for image processing (with 256x256 arrays), but it contains a "for loop" that make it slow. So I think it'd be faster in c++, but i'm just a beginner and i don't know how to work with 2D arrays.

My Matlab code is:

Code:

`[data2]=functionx(data,fx,fy) //data2 is an output array 256x256; data,fx,fy are 256x256 inputs`

[Lx,Ly]=size(data); //Lx is number of rows, Ly columns

data2 = zeros(Lx,Ly); //preallocate an array 2D

for x = 1:Lx-1

for y = 1:Ly-1

dx = x + fx(x,y);

dy = y + fy(x,y);

ix = floor(dx); //floor rounds the element dx to the nearest integer towards minus infinity

iy = floor(dy);

ax = 1 - (dx - ix);

ay = 1 - (dy - iy);

if ix>0 & iy>0 & ix<Lx & iy<Ly

data2(x,y) = ax*ay*data(ix,iy) + (1-ax)*ay*data(ix+1,iy) + ax*(1-ay)*data(ix,iy+1) + (1-ax)*(1-ay)*data(ix+1,iy+1);

end

end

end

Well, it isn't a difficult code and i don't ask for all it, only how to work with 2D arrays (create 2D arrays, arrays sum, access to a value). Thanks a lot for your time.