0

こんにちは。ご協力ありがとうございます。MATLAB を使用して 4 つのカラー グループで 3D 散布図を作成しました (アップロード、以下を参照)。ここで、時間に関して散布図をアニメーション化したいと思います。したがって、各ポイントにタイムスタンプがある場合は、それらを順番に表示したいと思います.

たとえば、車の特定の xyz 位置でエラーを悔い改めるポイント A、B、C があり、エラー A が午前 10 時に発生し、エラー B が午後 12 時に発生し、エラー C が午後 3 時に発生した場合、そのポイントをプロットしたいアニメで注文。

また、可能であれば、スクロール バーを備えた GUI を作成して、時間の経過または時間の経過とともにスクロールできるようにして、時間の経過とともにポイントを追加したり、時間を遡ってポイントを削除したりしたいと考えています。または、少なくともスケーター プロセスを一時停止するオプション。

注: 散布図には約 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)
4

1 に答える 1

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スクリプト全体が関数になる必要があることを意味します (これは、かなりのサイズの処理を実行するための適切な方法です)。

于 2012-08-23T14:13:24.090 に答える