slice用法介绍
load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)
官方文档介绍
[x,y,z] = meshgrid(-1.25:.1:-.25,-2:.2:2,-2:.1:2);
v = x.*exp(-x.^2-y.^2-z.^2);
% 指定切片的位置在xyz轴
h = slice(x,y,z,v,[-1 -.75 -.5],[],[0]);
set(h,'EdgeColor','none',...
'FaceColor','interp',...
'FaceAlpha','interp')
alpha('color')
alphamap('rampdown')
alphamap('increase',.1)
colormap hsv
pcolor3效果
%% example1
[x,y,z] = meshgrid(-2:.05:2,-2:.1:2,-2:.1:2);
v = x.*exp(-x.^2-y.^2-z.^2) + 1;
figure
pcolor3(v)
axis tight
%% example2
figure
pcolor3(x,y,z,v,'edgealpha',.1)
rgbmap('blue','white','red')
colorbar
caxis([0.8 1.2])
% camlight
view(160,36)
%% example3
figure
pcolor3(x,y,z,v,'cubic','edgealpha',.1)
% pcolor3(x,y,z,v,'alphalim',[1 1.2],'cubic','edgealpha',.1)
rgbmap('blue','white','red')
colorbar
caxis([0.8 1.2])
% camlight
view(160,36)
%% example4
[lon,lat,z] = meshgrid(-180:3:180,-80:2:80,0:100:2000);
T = 30 - .1*abs(lat) - .01*z + sind(lon);
figure
pcolor3(lon,lat,z,T,'direct')
% pcolor3(lon,lat,z,T,'direct','alphalim','auto')
% format:
xlabel('longitude')
ylabel('latitude')
zlabel('elevation (m)')
axis tight
set(gca,'xtick',[-180 -90 0 90 180],...
'ytick',[-45 0 45])
c = load('coast.mat');
plot(c.long,c.lat)
load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)
spinningGIF('123')
% spinningGIF(fname): makes a spinning GIF of the current plot and saves it
% Usage: make your 3D plot (using plot3(...) or scatter3(...) etc.) and
% then call SpinningGIF with the file name that you want
function spinningGIF(fname)
axis off
% view(0,10)
center = get(gca, 'CameraTarget');
pos = get(gca, 'CameraPosition');
radius = norm(center(1:2) - pos(1:2));
angles = 0:0.02*pi:2*pi;
for ii=1:length(angles)
angle = angles(ii);
set(gca, 'CameraPosition', [center(1) + radius * cos(angle),...
center(2) + radius * sin(angle),...
pos(3)]);
drawnow;
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if ii == 1
imwrite(imind,cm,fname,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,fname,'gif','WriteMode','append','DelayTime', 0.25);
end
end
end
OptionZ.FrameRate=15;OptionZ.Duration=5.5;OptionZ.Periodic=true;
CaptureFigVid([-20,10;-110,10;-190,80;-290,10;-380,10], 'WellMadeVid',OptionZ)
load mri
D = double(squeeze(D));
D(D==0)=nan;
h = slice(D, [], [], 1:size(D,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.4)
for az=0:5:355
view(az,36)
drawnow;
end