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

3 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2020-1-22
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 个评论
Willemijn Wolf
Willemijn Wolf 2020-1-23
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by