Need help initialising a 2D array

  • Thread starter Thread starter pamparana
  • Start date Start date
  • Tags Tags
    2d Array
AI Thread Summary
To initialize a 2D array 'phi' in MATLAB, the meshgrid function can be utilized to create matrices for the x and y coordinates. The equation phi(x, y) = 0.5 * (x^2 + y^2) can then be applied to these matrices to compute the values of phi at each pixel. This approach efficiently sets up the desired gradient, grad(phi(x, y)) = (x, y). Users are encouraged to refer to MATLAB documentation for additional guidance on meshgrid and plotting functions. This method effectively achieves the goal of creating the 2D array as specified.
pamparana
Messages
123
Reaction score
0
Hello everyone,

I have a newbie Matlab question. I need to set up a 2D array 'phi' whose gradient is an identity mapping in terms of the spatial coordinate.

So, basically I have a 2D image and what I want to do is set up phi at each pixel (x, y) as follows:

phi(x, y) = 0.5 * (x^2 + y^2), so that grad(phi(x, y)) = (x, y).

My question is how can I set this up in Matlab in an efficient way. So, given a 2D image, how can I set up this phi using the equation phi(x, y) = 0.5 * (x^2 + y^2).

Any help would be greatly appreciated.

Many thanks,

Luca
 
Physics news on Phys.org
Last edited by a moderator:
Back
Top