Understanding Meshgrid, interp3 and scatter3
5 ビュー (過去 30 日間)
古いコメントを表示
I have some 3d-simulation data I want to process in matlab using the scatter3 function, but despite reading all the documentation and looking for tips I'm stuck.
Current code:
load('TE_period_150nm_testres.mat');
Ex=Monitors.model_volumepower.Ex;
Ey=Monitors.model_volumepower.Ey;
Ez=Monitors.model_volumepower.Ez;
Ex=abs(Ex);
Ey=abs(Ey);
Ez=abs(Ez);
mag=sqrt(Ex.^2+Ey.^2+Ez.^2);
x=Monitors.model_volumepower.x;
y=Monitors.model_volumepower.y;
z=Monitors.model_volumepower.z;
x2 = linspace(min(x),max(x),max([length(x) length(y) length(z)]));
y2 = linspace(min(y),max(y),max([length(x) length(y) length(z)]));
z2 = linspace(min(z),max(z),max([length(x) length(y) length(z)]));
[X,Y,Z] = meshgrid(z,y,x);
[X2,Y2,Z2] = meshgrid(z2,y2,x2);
magnew = interp3(X,Y,Z,mag,X2,Y2,Z2);
Mag is a 61*74*53 matrix, x y and z are vectors of size 61, 74 and 53 respectively. I understand Mag needs to become an M*M*M-matrix to work for scatter3. I tried to make a new 74*74*74-matrix (spanning the same range) and use interp3 to interpolate required values. For some reason, all my magnew-values become NaN.
Who can help me out?
(If I can fix this, I'll still have four 3d-matrices (for x, y, z and magnitude) whereas scatter3 apparently needs one long vector. Can I just fix that using
for i=1:length(magnew).^3
magfinal(i)=magnew(i)
end
where I'm basically making it one long vector? (Same for x, y and z)
Thanks a lot in advance!
1 件のコメント
Chad Gilbert
2013 年 7 月 12 日
Generally, you would use scatter3 to do something like e.g. show where a set of data points are located in 3D. So it might be interesting to look at something like:
scatter3(x, y, z);
But you've interpolated a scalar value onto a regular 3D grid. It might be interesting to look at something like (untested):
scatter3(X(:),Y(:),Z(:),mag(:));
which will use the color of each scatter point to show you the color, but I would expect this to be quite ugly and difficult to make sense of. It's generally very hard to visualize a scalar field in 3D on a 2D monitor.
If it were me, I'd try plotting several 2D slices through the graph using pcolor.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!