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

混江龙づ霸主 提交于 2020-01-03 04:50:30

问题


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:


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.



来源:https://stackoverflow.com/questions/11454688/matlab-4d-3d-color-plot-with-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!