如何使用切片在圆柱网格上绘制数据? [英] How to plot data on a cylindrical grid using slice?
问题描述
我将输入数据存储在圆柱网格上,并希望使用MATLAB中的 slice
对其进行绘制.为此,我首先使用 pol2cart
将参考坐标转换为笛卡尔坐标.
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)
当我现在使用 slice
(例如 slice(xmesh,ymesh,zmesh,ones(10,4,3),2,2,2)
)时,出现错误因为坐标矩阵未正确排序而被抛出(输入网格不是有效的MESHGRID.
)
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.
从matlab文档中:
From the matlab documentation:
slice(X,Y,Z,V,sx,sy,sz) draws slices of the volume V. X, Y, and Z are three-dimensional arrays specifying the coordinates for V.
X, Y, and Z must be monotonic and orthogonally spaced (as if produced by the function meshgrid).
您可以做的是使用 griddata
.
这是一个示例:
r = linspace(1,4,4);
phi = linspace(0,2*pi,10);
z = linspace(1,3,3);
data = repmat(linspace(1,0,4),[10,1,3]);
[rmesh,phimesh,zmesh]=meshgrid(r,phi,z);
[xmesh,ymesh,zmesh]=pol2cart(phimesh,rmesh,zmesh);
[xg, yg, zg] = meshgrid(linspace(-4,4,50),linspace(-4,4,50),linspace(1,3,3));
gdata = griddata(xmesh,ymesh,zmesh,data,xg,yg,zg);
slice(xg,yg,zg,gdata,2,2,2)
根据您拥有的数据种类以及不显示超出范围"的数据(这意味着,按照您的示例:半径小于1或大于4)的重要性,您可以将以下内容添加到隐藏您不感兴趣的数据:
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:
rg = sqrt(xg.^2+yg.^2);
gdataNaN = gdata;
gdataNaN(rg<min(r)) = NaN;
gdataNaN(rg>max(r)) = NaN;
figure
slice(xg,yg,zg,gdataNaN,2,2,2)
如果这还不够,则您必须实现自己的 slice
方法(基本上使用griddata方法)或查看matlab中央文件交换.我尚未对其进行测试,但是用于分析MRI图像的工具可能可以解决问题(例如,请检查以下内容: http://www.mathworks.com/matlabcentral/fileexchange/27983-3d-slicer ).
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 ).
http://www.mathworks.com/matlabcentral/fileexchange/30147-smartslice-和igslice 这似乎是由具有相同问题的人开发的.
http://www.mathworks.com/matlabcentral/fileexchange/30147-smartslice-and-igslice this seems to have been developed by someone with the same problem.
这篇关于如何使用切片在圆柱网格上绘制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!