Effacer les filtres
Effacer les filtres

X,Y data of irregular grid, scatter plot with Z data

7 vues (au cours des 30 derniers jours)
Willemijn Wolf
Willemijn Wolf le 22 Jan 2020
Commenté : Star Strider le 23 Jan 2020
Dear all,
I know that there is the possibility to create a scatter plot using X and Y and reshaping the Z data, such that:
Z = reshape(Z, [X Y]);
figure()
imagesc (Z)
Square_xyz_2D_scatterplot.png
This creates a square 2D plot like depicted above.
However, I have a different problem now in which X,Y,Z data is already given to me (see text file attached).
The X,Y data include the coordinates of the center of a square. Z is the data that I would like to visualize by a scatter plot just like the example above. Now my 2D 'grid' on which I like to depect my Z data on looks like this:
irregular_2D_XY.jpg
So I have 2 questions
  1. Is there an easy way to create a nice rectangular grid out of these center points (still working with Matlab 2016, so no rectangle function yet...)? Or from the coordinates that I have on each node of one rectangular (see txt file attached).
  2. How to include my Z data such that I can create a scatter plot?
-> I know it is not a highly complicated problem, but I'm afraid that I might miss out some easy Matlab functions that are very convenient to use in my case.
Many thanks for any tips

Réponse acceptée

Star Strider
Star Strider le 22 Jan 2020
It is not obvious to me what you want.
You already appear to have tried reshape, although I have no idea what the arguments to it were, since we do not have that part of your code.
Try this:
filename = 'Demonstration_data_xyz.txt';
fidi = fopen(filename,'rt');
Dc = textscan(fidi, '%f%f%f%f%f%f%f%f%f%f%f%f', 'HeaderLines',1', 'CollectOutput',1, 'EndOfLine','\r\n', 'Delimiter',' ', 'MultipleDelimsAsOne',1);
Dd = [Dc{:}];
XYZ = Dd(:,10:12);
didx = diff([1; find(diff([0; XYZ(:,1)]) < 0));
Xmtx = reshape(XYZ(:,1), mean(didx), []);
Ymtx = reshape(XYZ(:,2), mean(didx), []);
Zmtx = reshape(XYZ(:,3), mean(didx), []);
figure
surf(Xmtx, Ymtx, Zmtx)
If this does not do what you want, please describe it in more detail. (I kept to functions that I remember being part of R2016b.)
  3 commentaires
Willemijn Wolf
Willemijn Wolf le 23 Jan 2020
Thank you for your help and sorry for the misunderstanding.
I was thinking in too difficult solutions while just using surf is exactly doing what I wanted
Star Strider
Star Strider le 23 Jan 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by