Creating a 2D color plot

44 次查看(过去 30 天)
Hi
I am trying to create a 2D plot from position vectors and a scalar I would like a figure with a continuous color image similar to this: http://www.ndt.net/article/v05n09/felix/fig13.jpg
What I have is:
- x positions as a vector
- y positions as a vector
- scalars as a vector
each vector containing 5228 values.
What might complicate things is that is that i have transformed the position vectors with an angle, since the data was generated using camaras that weren't completely lined up. The datapoints are thus not lined up with the axis.
I don't know if it makes a difference, but some of the scalar values were replaced with NaN and should be empty in the figure.
I wasn't able to find similar questions in here but if anyone can point me to a solution to this problem that would really help me out.
Thanks

采纳的回答

Walter Roberson
Walter Roberson 2015-6-17
编辑:Walter Roberson 2015-6-22
pointsize = 15;
scatter(x(:), y(:), scalars(:), pointsize, scalars(:))
However, if what you started with was a rectangular grid of data, and you rotated the axis, so what your data is "really" is still rectangular, then you should consider using mesh() or pcolor().
Supposing your original rectangular grid is orig_x and orig_y, then
[OX, OY] = ndgrid(orig_x, orig_y);
[OXYv] = [OX(:), OY(:)];
now do the rotation on the pairs x=OXYv(K,1), y=OXYv(K,2) to get Rxv, Ryv, vectors of the rotated values, in the same order as OXYv. Then
Rx = reshape(Rxv, size(OX));
Ry = reshape(Ryv, size(OX));
and then you can
pcolor(Rx, Ry, scalars)
Or you could have just taken your rectangular image, done an imrotate() on it to bring it into alignment with the axis, and image() the result.
Third method: make a hgtransform(), image() the rectangular matrix with 'Parent' being the hgtransform, then set the transform matrix to display the rectangular image at a tilt to the axis.
  1 个评论
Morten Mortensen
Morten Mortensen 2015-6-22
Hello. Thank you very much for your answer. I found another way, though.
[xq,yq] = meshgrid(....);
vq = griddata(x,y,v,xq,yq);
This makes interpolation of the data from vectors x,y,z onto the new positions xq and yq. This is just what I needed and it's very easy.
Thanks though!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by