我正在MATLAB中运行模拟,其中有一个大的3D数据集,每个时间步骤都会改变。我试图使用3D散点图来可视化数据,点的位置、大小、颜色和透明度随着模拟的进行而变化。大小和颜色信息是冗余的。
在MATLAB中渲染和旋转图形很慢且卡顿。我的计算机配备了4 GHz i7-4790 CPU和NVIDIA GeForce GTX 750 Ti显卡。我正在使用Windows 7上的Matlab R2016a。我检查了我的MATLAB OpenGL设置,硬件支持级别为全。 (透明度需要硬件OpenGL。) 此外,在绘制和旋转过程中,我使用GPU-Z监视我的GPU使用情况,GPU负载峰值仅达到25-30%。
以下是我的代码示例:
在MATLAB中渲染和旋转图形很慢且卡顿。我的计算机配备了4 GHz i7-4790 CPU和NVIDIA GeForce GTX 750 Ti显卡。我正在使用Windows 7上的Matlab R2016a。我检查了我的MATLAB OpenGL设置,硬件支持级别为全。 (透明度需要硬件OpenGL。) 此外,在绘制和旋转过程中,我使用GPU-Z监视我的GPU使用情况,GPU负载峰值仅达到25-30%。
以下是我的代码示例:
load sample_data2
channels_matrix = cat(1, channels{:});
num_channels = length(channels);
channel_lengths = cellfun(@(x) size(x, 1), channels);
figure(1);
for i = 1:num_channels
g = plot3(channels{i}(:, 1), channels{i}(:, 2), channels{i}(:, 3), 'k');
set(g, 'LineWidth', 1.5)
hold on;
text(channels{i}(1, 1), channels{i}(1, 2), channels{i}(1, 3), num2str(i))
end
caxis([0 1])
colorbar
drawnow
numDivisions = 8;
ptsPerDivision = numel(grid_x)/numDivisions;
T = 1000;
numplotpts = 2E4;
for t = 1:T
plot_signal = nan(size(grid_x));
plot_signal(sort(randsample(numel(grid_x), numplotpts))) =...
sort(rand(numplotpts, 1));
tic
for i = 1:numDivisions
temp = plot_signal(dists_idx((i-1)*ptsPerDivision+1:i*ptsPerDivision));
yplot = grid_y(dists_idx((i-1)*ptsPerDivision+1:i*ptsPerDivision));
xplot = grid_x(dists_idx((i-1)*ptsPerDivision+1:i*ptsPerDivision));
zplot = grid_z(dists_idx((i-1)*ptsPerDivision+1:i*ptsPerDivision));
if t == 1
h(i) = scatter3(yplot(~isnan(temp)), xplot(~isnan(temp)),...
zplot(~isnan(temp)), 50*temp(~isnan(temp)), temp(~isnan(temp)), ...
'filled', 'MarkerFaceAlpha', exp(-i)^0.25);
else
h(i).XData = yplot(~isnan(temp));
h(i).YData = xplot(~isnan(temp));
h(i).ZData = zplot(~isnan(temp));
h(i).SizeData = 50*temp(~isnan(temp));
h(i).CData = temp(~isnan(temp));
end
end
drawnow
toc
end
这里有一个指向data的链接。有没有办法加快渲染并使旋转更流畅?我注意到将所有数据点的大小固定为单个标量可以大大加快渲染和旋转速度。是否可能保持代码中的大小,仍然能够快速呈现和旋转图形?
编辑:我发布了一个相关问题。
drawnow
放在 for 循环内部(这可能是你想要看到变化的地方)。 - informaton