Creating a 2D color plot

60 Ansichten (letzte 30 Tage)
Morten Mortensen
Morten Mortensen am 17 Jun. 2015
Bearbeitet: Walter Roberson am 22 Jun. 2015
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Jun. 2015
Bearbeitet: Walter Roberson am 22 Jun. 2015
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 Kommentar
Morten Mortensen
Morten Mortensen am 22 Jun. 2015
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by