How to transform a XYZ-Array into a XxY-Matrix with Z as values of each Mxy-Component and vice versa?

22 ビュー (過去 30 日間)
Hi, I have a table XYZ with three columns (xyz) as below:
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
and I want to transform it into a Mxy-Matrix with Z as value for each Mxy pair as follows:
1 4 7
2 5 8
3 6 9
On the other hand I may have directly the Matrix Mxy and would like to obtain the XYZ-table.
I already tried mesh, meshgrid, ndgrid, surf and etc... as documented, but nothing worked as I wished. It is possible that I did not understand yet how to use this commands.
I wonder if someone could tell me how to write the command to convert:
1) Table XYZ to Matrix Mxy with Z as values of each Mxy-pair 2) Matrix Mxy to Table XYZ
I thank you in advance for your help
Emerson

採用された回答

Walter Roberson
Walter Roberson 2012 年 11 月 18 日
accumarray(XYZ(:,[2 1]), XYZ(:,3)]
  4 件のコメント
Emerson De Souza
Emerson De Souza 2012 年 11 月 19 日
Thank you Walter, your suggestions fixed my problem. Wish you a nice day
Emerson
Ander Del Olmo Sanz
Ander Del Olmo Sanz 2023 年 1 月 25 日
I have the same problem, but in my case values are not whole number, since it is the measurement of a 3D part, but i want just to sabe the values of Z axis, so what can I do for rationa number with commas, like 5,5 or 7.8 in X and Y axis ?

サインインしてコメントする。

その他の回答 (1 件)

Chad Greene
Chad Greene 2016 年 4 月 6 日
Thanks to Walter's excellent suggestion to use accumarray, I wrote an xyz2grid function to do this for GMT data.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by