How can I export x, y and z matrix to .xyz format file?

12 ビュー (過去 30 日間)
Z G
Z G 2019 年 12 月 16 日
コメント済み: Guillaume 2019 年 12 月 17 日
Hello everyone
Sincerely asking.
I have x,y and z matrix which the value of every (x,y,z) represent the location of a point. I can use "surf" to export a 3D picture. Now I want to know how can I export my x,y and z matrix to a .xyz fomat file. Please help me. Thank you!
with best wishes
  7 件のコメント
Z G
Z G 2019 年 12 月 17 日
For attaching the original file, I add ".txt' suffix to the original file that gwyddion can deal with. I want to export my matrix as original that can be dealed with by Gwyddion.
Guillaume
Guillaume 2019 年 12 月 17 日
The file you've attached contains a lot more than just x, y, z coordinates of points. It looks like it starts by an extensive text header. So you first need to know which of the header information, if any, is required and you'd need to supply that required information.
The header is then followed by some binary data, possibly the x, y, z coordinates. In order to even stand a chance to understand how the data is encoded as binary we would need the exact values that have been encoded in the file, and even then it would probably required a lot of work to reverse engineer. For this kind of file, the only reliable way to know how to create them is to have the specs of the format from whomever designed it.
I want to make it clear that a file extension on its own is meaningless, it doesn't necessarily represents what is actually in the file. You can slap a .xyz extension on any file and it doesn't mean that your software will be able to read it. For example, the answer you've accepted slaps a .xyz extension onto a file that contains tab delimited data but if your software expects a file in the format you've attached it will absolutely no idea what to do with that tab delimited file. The answer could be trivially modified to put a .xlsx extension onto the file, it wouldn't mean that excel could read it.

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

採用された回答

KSSV
KSSV 2019 年 12 月 17 日
Let X, Y, Z be your m, n matrices.
x = X(:) ;
y = Y(:) ;
z - Z(:) ;
p = [x y z] ;
fid = fopen('test.xyz', 'wt');
fprintf(fid, [repmat('%.f\t', 1, size(P,2)-1) '%f\n'],P.');
fclose(fid)
  4 件のコメント
Z G
Z G 2019 年 12 月 17 日
Though I still can't deal with the data in Gwyddion, I successfully expot matix to .xyz file from Matlab and import the file into Gwyddion by your code. So, I think it is enough.
On the way to solving the problem, every little progress deserves to be recognized. Even if that didn't end the problem, it hlep me to adjust direction.
Thank you.
Guillaume
Guillaume 2019 年 12 月 17 日
This exports the data as a tab delimited text file. It puts a .xyz extension to that file, it doesn't mean that's what expected by your software at all. It could have put a .xlsx extension onto it, it wouldn't mean that's a file that excel can read.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by