【发布时间】:2011-02-09 00:42:15
【问题描述】:
如果我在 Matlab 中使用 image() 命令制作一个 4 x 4 像素的图像,它会将刻度线居中在像素的中间。我希望刻度线位于像素的左下角。有没有办法做到这一点?
【问题讨论】:
标签: image matlab plot center axis-labels
如果我在 Matlab 中使用 image() 命令制作一个 4 x 4 像素的图像,它会将刻度线居中在像素的中间。我希望刻度线位于像素的左下角。有没有办法做到这一点?
【问题讨论】:
标签: image matlab plot center axis-labels
尝试以下方法:
a = randi([0 255], [4 4]);
figure, imagesc(a), caxis([0 255])
b = zeros( size(a)+1 );
b(1:end-1,1:end-1) = a;
figure, pcolor(b), caxis([0 255]), axis ij
请注意,我扩展了矩阵 a,因为 pcolor 删除了最后一行/列。
【讨论】:
我认为这段代码会做你想做的事。它只在像素的边缘放置刻度线:
A = ...; %# Your 4-by-4 matrix
image([0.5 3.5],[0.5 3.5],A); %# Pixel edges are at 0, 1, 2, 3, and 4
set(gca,'XTick',0:4,'YTick',0:4); %# Place tick marks at 0, 1, 2, 3, and 4
【讨论】:
您可以指定像素的 x 和 y 坐标并将它们移动 0.5:
image([0.5,3.5],[0.5,3.5],magic(4))
【讨论】: