2D plot from 3D Datasets

3 次查看(过去 30 天)
Hassan Strong
Hassan Strong 2020-6-21
评论: darova 2020-6-24
Hello,
I uploaded 3D datasets like this (given in Imz) and I can plot 3D slice as well. But now I want to plot each of the 2D slice seperately how can I do that?
clc
clear all
close all
%%%%Initialize
scaLe=0.01
pixel_endpointx=16*scaLe;
pixel_endpointy=16*scaLe;
pixel_endpointz=45*scaLe;
x_n=linspace(-pixel_endpointx,pixel_endpointx,50);
y_n=linspace(-pixel_endpointy,pixel_endpointy,50);
z_n=linspace(-pixel_endpointz,pixel_endpointz,50);
X1=x_n;
Y1=y_n;
Z1=z_n;
[x_n,y_n,z_n]=meshgrid(X1,Y1,Z1);
x_n=x_n(:);
y_n=y_n(:);
z_n=z_n(:);
%%%%%%for plot
x1=x_n;
y1=y_n;
z1=z_n;
X=x_n;
Y=y_n;
Z=z_n;
Imz=csvread('Image_pixel.csv') %%%%size is row=50*50*50 by 1 column
range=100
xlin = linspace(min(X),max(X),range);
ylin = linspace(min(Y),max(Y),range);
zlin=linspace(min(Z),max(Z),range);
[XX,YY,ZZ] = meshgrid(xlin,ylin,zlin);
zi = griddata(x1,y1,z1,Imz./(max(Imz)),XX,YY,ZZ); %%%%interpolation
xslice = [-5]*scaLe;
yslice = [-3]*scaLe;
zslice = [-20,15]*scaLe;
slice(XX,YY,ZZ,zi,xslice,yslice,zslice)
colormap(jet(256))
colorbar
shading interp;

回答(1 个)

darova
darova 2020-6-23
try this way
zslice = [-20,15]*scaLe;
figure
slice(XX,YY,ZZ,zi,xslice,[],[])
figure
slice(XX,YY,ZZ,zi,[],[],zslice(1))
figure
slice(XX,YY,ZZ,zi,[],[],zslice(2))
figure
slice(XX,YY,ZZ,zi,[],yslice,[])
  2 个评论
Hassan Strong
Hassan Strong 2020-6-23
Hi, I was asking 2D plot not 3D plot.
darova
darova 2020-6-24
Sorry, forgot about 2D. Try this
[x,y,z] = meshgrid(-2:.2:2,-2:.25:2,-2:.16:2);
v = x.*exp(-x.^2-y.^2-z.^2);
h = slice(x,y,z,v,1,[],[]);
pcolor(get(h,'cdata'))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by