除了存在绘制矢量场的特殊函数这一事实之外,我还遇到了一个奇怪的 Matlab 行为:绘制图像(使用imagesc
or )并用彩色线条(使用or )imshow
覆盖它会在某些时候导致背景图像的擦除。plot
line
%% some data...
% random image
Image = rand(200,400);
% 900 lines of random color
color1 = rand(1,900);
color2 = rand(2,900);
color3 = rand(3,900);
% some positions
x = 31:60;
y = 31:60;
[X,Y] = meshgrid(x,y);
%% plot process
% plot Image (with 'imshow' or 'imagesc')
imshow(Image);
hold on;
% plot the lines (with 'line' or 'plot')
for i = 1:900
line([X(i), X(i)+1],[Y(i),Y(i)+2],'color',[color1(i),color2(i),color3(i)]);
if i == 100 % nothings happens to background image after 100 vectors
pause();
elseif i == 200 % gradually starts to change...
pause();
end
end
% ... at the end it is completely erased
结果:100 行
结果:200 行
结果:900 行
好的一面是将图像保存为 PNG 可以恢复图像(但会破坏线条分辨率)。