Creating a 2D color plot

조회 수: 59 (최근 30일)
Morten Mortensen
Morten Mortensen 2015년 6월 17일
편집: Walter Roberson 2015년 6월 22일
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에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by