How can I export x, y and z matrix to .xyz format file?
12 次查看(过去 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 中查找有关 Workspace Variables and MAT Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!![@2CB7BVBNK]0TE6H)U4WV`K.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/254757/@2CB7BVBNK]0TE6H)U4WV`K.png)
