2012-08-23 90 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,這意味着你的整個腳本需要成爲一個功能(這是真的做任何明顯的大小事情反正有道)。