From: Anthony Hopf on
The last time I posted I was trying to take elements in a grid indexed in cartesian coordinates and express those elements in a grid indexed in spherical coordinates. I did this by creating a fine spherical grid and using the interp3 function filling in this grid. The interpolation created bias in the statistics of the information within the elements... so I would like to do this a different way and need a hand.

I would still like to place the elements in the cartesian grid into a spherical grid, but I want to do so while still keeping track of the cartesian grid index. Can someone please tell me how you would go about placing the cartesian indexed elements into a spherical grid with indexes based on spherical coordinates? I know this new grid will not be fully populated, and I know there will be some rounding that needs to be done to establish a common gridding index in spherical. Is there an "easy" way to do this and still keep track of the cartesian indexes?

Thank you again,

Tony
From: us on
"Anthony Hopf" <anthony.hopf(a)gmail.com> wrote in message <hrmett$r8v$1(a)fred.mathworks.com>...
> The last time I posted I was trying to take elements in a grid indexed in cartesian coordinates and express those elements in a grid indexed in spherical coordinates. I did this by creating a fine spherical grid and using the interp3 function filling in this grid. The interpolation created bias in the statistics of the information within the elements... so I would like to do this a different way and need a hand.
>
> I would still like to place the elements in the cartesian grid into a spherical grid, but I want to do so while still keeping track of the cartesian grid index. Can someone please tell me how you would go about placing the cartesian indexed elements into a spherical grid with indexes based on spherical coordinates? I know this new grid will not be fully populated, and I know there will be some rounding that needs to be done to establish a common gridding index in spherical. Is there an "easy" way to do this and still keep track of the cartesian indexes?
>
> Thank you again,
>
> Tony

a small and usable code example would be more useful than your many words...

us
From: Anthony Hopf on
>
> a small and usable code example would be more useful than your many words...
>
> us

us, That makes sense... let me see

if we start with

delta_xyz = 10; %uniform index factor
[x y z]=meshgrid((1:10)*delta_xyz,(1:10)*delta_xyz,(1:10)*delta_xyz); % x,y,z corresponding to values of v; v(i,j,k) is at [x(i,j,k),y(i,j,k),z(i,j,k)] in "space"
v = magic(size(x)); %I am just setting arbitrary values at this point
[theta phi r] = cart2sph(x,y,z); % here are the corresponding spherical coordinates to each v.

what I would like to do now is create a 3d table of v, called v', that is indexed by the theta phi and r, and is sorted so theta is along the "x axis", phi is along the "z axis" and r is along the "y axis". I would also like to keep track of my indexes so I can easily go back to the original table v.

v'(theta(i,j,k),r(i,j,k),phi(i,j,k)) = v(x(i,j,k),y(i,j,k),z(i,j,k))% for all values of v

The thing about v' is that I would like to have a easily indexed grid. This would mean that there would need to be a constant delta_theta, delta_r, and delta_phi that would allow me to quickly filter or look up values within this grid. This would create empty element within the v' 3d matrix, which would be no problem to me. As long as I can continue to keep track of the x,y,z indexes of each of the values I put into v' then I am fine.

I know there is still a lot of text, but can anyone help?
From: Bruno Luong on
"Anthony Hopf" <anthony.hopf(a)gmail.com> wrote in message <hrmm2l$kbf$1(a)fred.mathworks.com>...

> I know there is still a lot of text, but can anyone help?

If you take a closer look of the solution I posted in your last thread, the indexing is provided in the variable called LOC:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/280488

Bruno