I have input data on a cylindrical grid and want to plot them using slice
in MATLAB.
To do this I first transform the reference coordinates into Cartesian coordinates using pol2cart
.
r = linspace(1,4,4);
phi = linspace(0,2*pi,10);
z = linspace(1,3,3);
[rmesh,phimesh,zmesh]=meshgrid(r,phi,z)
[xmesh,ymesh,zmesh]=pol2cart(phimesh,rmesh,zmesh)
When I use slice
now (e.g. slice(xmesh,ymesh,zmesh,ones(10,4,3),2,2,2)
) an error is thrown, because the coordinate matrices are not ordered correctly (Input grid is not a valid MESHGRID.
)
How can I modify the matrices to get a plottable result?
Sadly you cannot use data given in cylindrical coordinates for usage with slice.
From the matlab documentation:
What you can do is use
griddata
.here is an example:
Depending on what kind of data you have and how important it is not to display data that is 'out of bounds' (meaning, following your example: of radius smaller than 1 or larger than 4) you can add the following to hide data that is out of your area of interest:
If that isn't enough you would have to implement your own
slice
method (basically using the griddata method) or look on matlab central fileexchange. I haven't tested it, but tools for analyzing MRI images might do the trick (check, for example, this: http://www.mathworks.com/matlabcentral/fileexchange/27983-3d-slicer ).EDIT: http://www.mathworks.com/matlabcentral/fileexchange/30147-smartslice-and-igslice this seems to have been developed by someone with the same problem.