具有三列的 matlab 颜色图
matlab colormap with three columns
我想在matlab中画一个三列的彩图。
我可以像下面那样用 plot3
画画,
x = [1 1 1 1 2 2 2 2 4 4 4 4 5 5 5 5 9 9 9 9];
y = [2 3 4 5 5 6 7 8 4 5 6 7 1 2 3 4 7 8 9 10];
z = [1 3 2 4 5 6 7 3 9 8 8 9 2 4 3 5 1 2 3 1];
plot3(x, y, z, 'o')
但是如何绘制三列的二维彩图呢?
选项 1:
如果我对你的理解正确,你想绘制一个二维数组(比如 m(x,y)
),其中颜色由 z
给出。是这样的:
m=zeros(max(x),max(y)); % preallocate m according to values of x,y
m(sub2ind(size(m),x,y))=z; % assign z-values to the x,y coordinates
imagesc(m) % plot
colormap(pink(max(z))); % set colormap with the dynamic range of z.
% you can replace it with jet or whatever...
colorbar % add a colorbar
选项 2:
您真的只想从 x,y,z
:
创建 am RGB 颜色图
cmap=[x(:) y(:) z(:)]./max([x(:);y(:);z(:)]);
imagesc(peaks(100));
colormap(cmap);
我想在matlab中画一个三列的彩图。
我可以像下面那样用 plot3
画画,
x = [1 1 1 1 2 2 2 2 4 4 4 4 5 5 5 5 9 9 9 9];
y = [2 3 4 5 5 6 7 8 4 5 6 7 1 2 3 4 7 8 9 10];
z = [1 3 2 4 5 6 7 3 9 8 8 9 2 4 3 5 1 2 3 1];
plot3(x, y, z, 'o')
但是如何绘制三列的二维彩图呢?
选项 1:
如果我对你的理解正确,你想绘制一个二维数组(比如 m(x,y)
),其中颜色由 z
给出。是这样的:
m=zeros(max(x),max(y)); % preallocate m according to values of x,y
m(sub2ind(size(m),x,y))=z; % assign z-values to the x,y coordinates
imagesc(m) % plot
colormap(pink(max(z))); % set colormap with the dynamic range of z.
% you can replace it with jet or whatever...
colorbar % add a colorbar
选项 2:
您真的只想从 x,y,z
:
cmap=[x(:) y(:) z(:)]./max([x(:);y(:);z(:)]);
imagesc(peaks(100));
colormap(cmap);