我需要生成 2000 个 2D 多元高斯分布样本,其平均值为 [2;3] 且协方差 C = [0.2 0; 0 0.3]在朱莉娅。是否可以使用 Distributions 包中的 MvNormal 函数来做到这一点?
提前致谢。
我正在尝试创建一个动画情节,但是我的代码非常慢,也许我使用的方法太幼稚了。在下面的示例中,我有4个子图,每个子图有3行,并在“时间”循环中进行了更新。
clc;clear;close all;
state = {'$x-Position$','$x-Velocity$','$y-Position$','$y-Velocity$'};
ylabels = {'$x$','$\dot{x}$','$y$','$\dot{y}$'};
options1 = {'interpreter','latex'};
options2 = {'interpreter','latex','fontsize',20};
maxT = 300;
for pp = 1:4
hh1(pp)=subplot(2,2,pp);
xlabel('$t$',options2{:});
ylabel(ylabels{pp},options2{:});
title(state{pp},options1{:})
xlim([0 maxT])
hold on
end
x = randn(4,300);
z = randn(4,300);
x_est = randn(4,300);
for k = 2:maxT
for p = 1:4
plot(hh1(p),k-1:k,x(p,k-1:k),'b','linewidth',2)
plot(hh1(p),k-1:k,z(p,k-1:k),'m')
plot(hh1(p),k-1:k,x_est(p,k-1:k),':k','linewidth',2)
end
drawnow;
end
Run Code Online (Sandbox Code Playgroud)
从探查器输出中可以看出,这drawnow正在浪费时间。有什么方法可以使我更有效地创建此动画?