How can I export x, y and z matrix to .xyz format file?
조회 수: 46 (최근 30일)
이전 댓글 표시
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
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
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
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 Exchange에서 Language Support에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!