X,Y data of irregular grid, scatter plot with Z data
8 次查看(过去 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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/265823/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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/265824/irregular_2D_XY.jpeg)
So I have 2 questions
- 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).
- 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!