Matlab-尝试在彩色图的每个点上使用带有网格坐标和值的向量 [英] Matlab - Trying to use vectors with grid coordinates and value at each point for a color plot

查看:140
本文介绍了Matlab-尝试在彩色图的每个点上使用带有网格坐标和值的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用另一个程序的输出数据在matlab中绘制颜色图.我有3个向量,分别指示x位置,y位置(均以毫秒为单位,因为这表示黑洞周围的图像)以及所需点中每个点的值(将为其指定颜色)图像.我显然不能使用pcolor,因为指示每个像素"颜色的值不在矩阵中,而且除了meshgrid之外,我不知道从矢量中创建矩阵的其他方法,但没有由于向量的大小而起作用.

I'm trying to make a color plot in matlab using output data from another program. What I have are 3 vectors indicating the x-position, y-yposition (both in milliarcseconds, since this represents an image of the surroundings of a black hole), and value (which will be assigned a color) of every point in the desired image. I apparently can't use pcolor, because the values which indicate the color of each "pixel" are not in a matrix, and I don't know a way other than meshgrid to create a matrix out of the vectors, which didn't work due to the size of the vectors.

在此先感谢您的帮助,我可能无法立即回复.

Thanks in advance for any help, I may not be able to reply immediately.

推荐答案

如果我们不对x,y坐标的排列(即非单调)和数据样本的稀疏性做任何假设,那是获得数据的最佳方法向量中的一个不错的图像是使用TriScatteredInterp.这是一个示例:

If we make no assumptions about the arrangement of the x,y coordinates (i.e. non-monotonic) and the sparsity of the data samples, the best way to get a nice image out of your vectors is to use TriScatteredInterp. Here is an example:

% samplesToGrid.m
function [vi,xi,yi] = samplesToGrid(x,y,v)

F = TriScatteredInterp(x,y,v);
[yi,xi] = ndgrid(min(y(:)):max(y(:)), min(x(:)):max(x(:)));
vi = F(xi,yi);

下面是在100x100网格上获取500个像素"样本并构建完整图像的示例:

Here's an example of taking 500 "pixel" samples on a 100x100 grid and building a full image:

% exampleSparsePeakSamples.m
x = randi(100,[500 1]); y = randi(100,[500 1]);
v = exp(-(x-50).^2/50) .* exp(-(y-50).^2/50) + 1e-2*randn(size(x));
vi = samplesToGrid(x,y,v);
imagesc(vi); axis image

如果坐标是整数值,则戈登的答案将有效,但是图像将是多余的.

Gordon's answer will work if the coordinates are integer-valued, but the image will be spare.

这篇关于Matlab-尝试在彩色图的每个点上使用带有网格坐标和值的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆