MATLAB 4D (3d + color) plot with animation

2019-06-13 20:49发布

I have 3 sets of 30 data points X,Y,Z. I would like to make the 4th dimension color. However the 4th dimension I want to use is a different length than my X,Y,Z (133 vs 30).

This is a problem when using the scatter3 function in MATLAB, as the color dimension must match the size of X,Y,Z.

I also want to animate this plot in .avi format, and have the 4th dimension (color) change as the movie progresses.

Thanks in advance.

1条回答
干净又极端
2楼-- · 2019-06-13 21:14

Create a 2D or 3D matrix to define your colors: 2D if you use colors indexed into the colormap, or 3D if you want to give RGB values.

X=1:30;Y=randperm(30);Z=ones(size(X));
voltage_matrix = ...; %# 30 by 133 
cdata = voltage_matrix;
handle = scatter3(X,Y,Z);

colormap('jet')
set(gca,'clim',[min(voltage_matrix) max(voltage_matrix)])

for t=1:size(cdata,2) %# 1 to 133
    set(handle, 'cdata', cdata(:,t));
    pause(.1)
end

Edit: note the colormap and axes 'clim' property.

查看更多
登录 后发表回答