-
Notifications
You must be signed in to change notification settings - Fork 0
/
savevtk.m
30 lines (30 loc) · 913 Bytes
/
savevtk.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function savevtk(array, filename)
% savevtk Save a 3-D scalar array in VTK format.
% savevtk(array, filename) saves a 3-D array of any size to
% filename in VTK format.
[nx, ny, nz] = size(array);
fid = fopen(filename, 'wt');
fprintf(fid, '# vtk DataFile Version 2.0\n');
fprintf(fid, 'Comment goes here\n');
fprintf(fid, 'ASCII\n');
fprintf(fid, '\n');
fprintf(fid, 'DATASET STRUCTURED_POINTS\n');
fprintf(fid, 'DIMENSIONS %d %d %d\n', nx, ny, nz);
fprintf(fid, '\n');
fprintf(fid, 'ORIGIN 0.000 0.000 0.000\n');
fprintf(fid, 'SPACING 1.000 1.000 1.000\n');
fprintf(fid, '\n');
fprintf(fid, 'POINT_DATA %d\n', nx*ny*nz);
fprintf(fid, 'SCALARS scalars double\n');
fprintf(fid, 'LOOKUP_TABLE default\n');
fprintf(fid, '\n');
for a=1:nz
for b=1:ny
for c=1:nx
fprintf(fid, '%d ', array(c,b,a));
end
fprintf(fid, '\n');
end
end
fclose(fid);
return