2012-08-23 127 views
0

你好,先谢谢你的帮助! 我用MATLAB制作了4个颜色组的3D散点图(上传,见下文)。 现在我想根据时间对散点图进行动画处理。所以如果每个点都有时间戳,我想按顺序显示它们。因此,例如:如果我有A,B,C点在车辆的特定xyz位置上悔改错误,并且错误A是在上午10点制作的,错误B在12PM,错误C在3PM,我想绘制动画中的顺序点。动画3D组散点图关于时间MATLAB

另外如果可能的话,我想用滚动条做一个GUI,这样我就可以滚动时间或回到时间,从而在我回到时间的同时前进时间或删除点时添加点。或者至少有一个选项可以暂停scater进程。

注:散点图将有大约2000-3000点......我不知道这是否会有所作为。我也是MATLAB新手:-)

非常感谢您的帮助和时间! 亲切的问候

阿尔弗雷多


%Scatterplot data 

x = [ 50 55 200 210 350 360 400 450 550 560 600 670 750 850 860]; 
y = [ 50 -50 100 -100 150 -150 151 -151 150 -150 152 -152 150 -150 150]; 
z = [ 120 120 100 300 100 300 100 300 100 300 100 300 100 300 100]; 

% alocates space for the z data by creating a matrix array of all ones 
g = [0*ones(3,1);1*ones(3,1); 2*ones(3,1); 3*ones(3,1); 4*ones(3,1); ]; 

%set specific RGB color value for positions 0-4 and background color 
color = [0 0 0; 1 0 0; 0 0 1; 1 1 0; 0 1 0] 

whitebg([ 0.6758 0.8438 0.8984]) % light blue background 


% gscatter creates a 2D matrix with the values from x and y 
% and creates groups acording to the 'g' matrix size 
% h = gscatter captures output argument and returns an array of handles to the lines on the graph) 
h = gscatter(x, y, g, color) 

%% for each unique group in 'g', set the ZData property appropriately 
gu = unique(g); 
for k = 1:numel(gu) 
set(h(k), 'ZData', z(g == gu(k))); 
end 

%set the aspect ratio, grid lines, and Legend names for the 3D figure 
daspect([4.5 5 5]) 
grid on 
legend('Position 0','Position 1','Position 2','Position 3','Position 4') 

% view a 3D grapgh (for 2D set to "2") 
view(3) 
+0

嗨,欢迎来到SO!请注意,在这里通常会意识到,每个帖子只会提出一个问题,并且保持问题简短并且重点突出。 –

回答

0

如果我理解正确的话,你只想一个接一个显示所有的不同的散点图。这很简单,只需将其附加到您的代码:

% loop through time 
xl = xlim; 
yl = ylim; 
zl = zlim; 
for ii = h(:).' 
    % switch all scatter plots off 
    set(h, 'visible', 'off') 
    % switch only 1 on, for the current time 
    set(ii, 'visible', 'on'); 

    % set original limits 
    xlim(xl); ylim(yl); zlim(zl); 

    % draw and some delay 
    drawnow, pause(1); 
end 

至于滑块,下面是一个如何做到这一点的例子。追加这对你的代码:

xl = xlim; 
yl = ylim; 
zl = zlim; 

slider = uicontrol(... 
    'parent', gcf,... 
    'style', 'slider',... 
    'min', 0,... 
    'max', 4,... 
    'sliderstep', [1/4 1/4],... 
    'units', 'normalized',... 
    'position', [0.05 0.05 0.90 0.05],...  
    'callback', @SliderCallback); 

function SliderCallback(sliderObj, ~) 
    set(h, 'visible', 'off') 
    set(h(get(sliderObj, 'Value')+1), 'visible', 'on') 
    xlim(xl); ylim(yl); zlim(zl); 
end 

注意,这里使用一个嵌套function,这意味着你的整个脚本需要成为一个功能(这是真的做任何明显的大小事情反正有道)。