Matlab中的动画3D散点图 [英] Animated 3D Scatter-Plot in Matlab

查看:197
本文介绍了Matlab中的动画3D散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据,总共有4个自变量,我认为表示4个自变量和一个因变量的唯一方法是为3D散点图制作动画.

I have a set of data with a total of 4 independent variables, and I figure the only way to represent 4 independent variables and one dependent variables is to animate a 3D scatter-plot.

假设我有以下数据集:

W X Y Z Val
0 0 0 0 5.5
0 0 0 1 2.3
0 0 1 0 1.6
0 0 1 1 8.8
0 1 0 0 2.6
0 1 0 1 4.8
0 1 1 0 0.1
0 1 1 1 1.1
1 0 0 0 1.0
1 0 0 1 0.0
1 0 1 0 0.4
1 0 1 1 4.4
1 1 0 0 4.4
1 1 0 1 7.9
1 1 1 0 9.1
1 1 1 1 2.3

然后读取值并将其转换为以下数组:

And the values were read in and converted to the following arrays:

W = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}
x = {0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1}
X = {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1}
Z = {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}
Val = {5.5,2.3,1.6,8.8,2.6,4.8,0.1,1.1,1.0,0.0,0.4,4.4,4.4,7.9,9.1,2.3}

我想知道如何创建一个3D散点图(scatter3),其中X,Y和Z为自变量,Val以点的颜色表示,并相对于变量W进行动画处理.时间?

I'm wondering how to create a 3D scatter-plot (scatter3) with X, Y, and Z as the independent variables, Val as represented by the colors of the dots, and to animate with respect with the variable W as time?

基本上,当针对X,Y和Z在不同的时间绘制W = 0和W = 1时Val的不同值时.

Basically, when the different values of Val for when W=0 and W=1 are plotted at different times with respect to X, Y, and Z.

推荐答案

根据您的修改,我对建议进行了一些细化:

Based on your edit, I have slightly refined my suggestions:

mat=cell2mat([W;x;X;Z;Val])'; %Convert cells into a matrix

colors=prism(numel(mat(:,1)));
scatter3(mat(1,2),mat(1,3),mat(1,4),100,colors(1,:),'filled');
axis tight;

for jj=1:8:numel(mat(:,1))
    scatter3(mat(jj:jj+7,2),mat(jj:jj+7,3),...
        mat(jj:jj+7,4),100,colors(jj:jj+7,:),'filled');
    drawnow
    pause(1)
end

在上面的示例中,颜色是顺序分配的,但是如果您希望在VAL相同的情况下颜色相同,则可以执行以下操作:

In the above example the colors are sequentially assigned, but if you want the colors to be the same where VAL is the same, you could do something like the following:

mat=cell2mat([W;x;X;Z;Val])';
val_new=mat(:,5)/max(mat(:,5)); %0<VAL<1
scatter3(mat(1,2),mat(1,3),mat(1,4),100,[0 val_new(1) 0],'filled');
axis tight;

for jj=1:8:numel(mat(:,1))
    scatter3(mat(jj:jj+7,2),mat(jj:jj+7,3),...
        mat(jj:jj+7,4),100,[zeros(8,1) val_new(jj:jj+7,:) zeros(8,1)],'filled');
    drawnow
    pause(1)
end

当然,这两个示例都假设您每次始终有8个条目.在第二种情况下,有时会出现颜色差异很小的情况.如果要实际保存视频或动画gif,只需查看getframeimwrite.

Of course, both these examples assume that you will consistently have 8 entries at each time. And in the second instance there will be occasions where the differences in the colors are only very slight. If you want to actually save a video or a animated gif, just take a look at getframe and imwrite.

这篇关于Matlab中的动画3D散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆