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)

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:

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!