[vtkusers] Creating vtk-data from matlab

Dominik Szczerba domi at vision.ee.ethz.ch
Wed Jan 10 07:50:53 EST 2007


Discussion belongs to the list please.

You can export your matrix into a legacy ascii file (codelet below, you
will need to add some obvious things) or visualize it directly from
matlab (search for vtk matlab wiki)

--DS


fwid = fopen(set.vtkname,'w','b'); % IMPORTANT: big endian
count = fprintf(fwid,'# vtk DataFile Version 2.0\n');
count = fprintf(fwid,[set.remark,'\n']);
if set.ascii
    count = fprintf(fwid,'ASCII\n');
else
    count = fprintf(fwid,'BINARY\n');
end
count = fprintf(fwid,'DATASET STRUCTURED_POINTS\n');
count = fprintf(fwid,'DIMENSIONS %u %u %u\n',set.dim);
count = fprintf(fwid,'ORIGIN %u %u %u\n',set.origin);
count = fprintf(fwid,'SPACING %3.2f %3.2f %3.2f\n',set.spacing);
count = fprintf(fwid,'POINT_DATA %u\n',np);
count = fprintf(fwid,['SCALARS ',set.varname,' ',vtkprecision,' 1\n']);
count = fprintf(fwid,'LOOKUP_TABLE default\n');

% write data to vtk file
tic
fprintf(1,['writing ',set.vtkname,' ... ']);
if ~set.ascii
    count = fwrite(fwid, M, set.precision);
else
    fprintf(fwid, '%g \n', M);
end
fclose(fwid);
fprintf(1,'done in %5.3f s\n',toc);


Arne Hansen wrote:
> Its a volume. Actually I have several volumes i need to save.
>  
> Do you know how i can do this? :)
> thanks bro
> 
>  
> 2007/1/10, Dominik Szczerba <domi at vision.ee.ethz.ch
> <mailto:domi at vision.ee.ethz.ch>>:
> 
>     Of course. What data? mesh, volume?
>     --ds
> 
>     Arne Hansen wrote:
>     > Hello. Is there any way that i can save my matlab data in a file
>     > readable by vtk? If possible it would be great if this data could be
>     > saved in a *.vtk file from within matlab.
>     >
>     > Is this possible, if yes, how can i do it?
>     >
>     > Thank you.
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > This is the private VTK discussion list.
>     > Please keep messages on-topic. Check the FAQ at:
>     http://www.vtk.org/Wiki/VTK_FAQ
>     > Follow this link to subscribe/unsubscribe:
>     > http://www.vtk.org/mailman/listinfo/vtkusers
>     <http://www.vtk.org/mailman/listinfo/vtkusers>
> 
> 



More information about the vtkusers mailing list