gpt4 book ai didi

matlab - 颜色条减慢情节

转载 作者:行者123 更新时间:2023-12-05 03:15:05 28 4
gpt4 key购买 nike

我正在同一轴上循环绘制许多图像来制作视频。不幸的是,颜色条的存在使循环变慢了很多。即使我使用 caxis('manual')“卡住”了颜色条,也会发生这种情况。

为什么?我想仍然会有听众放慢整件事的速度,但这真的很糟糕。卡住颜色条后,不应进行任何计算。

这里有一个演示,演示了颜色条的一些工作原理,主要是为了卡住它。下面没有循环。

close all
figure(1);
C = gallery('randcorr',10);
ih = imagesc(1*C);
ch = colorbar;
% The colorbar disappears...
ih = imagesc(2*C);
% Must hold plot in order for it not to disappear
hold on
ch = colorbar;
% Now, even though it doesn't disappear, it still changes!
ih = imagesc(3*C);
% Even if we use a lower lever function
set(ih,'CData',4*C);
% We must do this to freeze the colorbar
caxis('manual')
set(ih,'CData',5*C);
ih = imagesc(6*C);
% That worked!

最佳答案

这比我想象的更有趣。我没有答案,但有一系列示例展示了一些非答案。也许比我聪明的人会有更好的运气。

例如,带有颜色条:

figure;
C = gallery('randcorr',10);
ih = imagesc(1*C);
ch = colorbar;
caxis([-2 2])
tic;
for ix = 1:100
set(ih,'CData',gallery('randcorr',10));
drawnow
end
toc; %2.7 seconds

没有颜色条

figure;
C = gallery('randcorr',10);
ih = imagesc(1*C);

caxis([-2 2])
tic;
for ix = 1:100
set(ih,'CData',gallery('randcorr',10));
drawnow
end
toc; %0.67 seconds

是什么导致了从 2.7 到 0.67 秒的变化?

颜色条实际上只是一种特殊的轴,所以问题可能在于图中有多个有趣的轴

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
C = gallery('randcorr',10);
ih2 = imagesc(1*C);

caxis([-2 2])
tic;
for ix = 1:100
set(ih,'CData',gallery('randcorr',10));
drawnow
end
toc; %0.87 seconds (consistently slower, but not enough)

也许是属性链接导致了速度变慢

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
C = gallery('randcorr',10);
ih2 = imagesc(1*C);
link = linkprop(get(gcf,'children'), 'CLim');

caxis([-2 2])
tic;
for ix = 1:100
set(ih,'CData',gallery('randcorr',10));
drawnow
end
toc; %0.88 seconds (pretty much the same as above)

查看默认颜色条,它有很多颜色细节,也许问题只是需要渲染的颜色数量。

figure;
subplot(2,1,1)
C = gallery('randcorr',10);
ih = imagesc(1*C);
subplot(2,1,2)
ih2 = imagesc(repmat(linspace(-2,2,200), 10,1));

caxis([-2 2])
tic;
for ix = 1:100
set(ih,'CData',gallery('randcorr',10));
drawnow
end
toc; %0.96 seconds (slower, but still not the 2.7 second colorbar case)

关于matlab - 颜色条减慢情节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21315626/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com