I would like to read a vtu file containing the solution of a problem in Matlab.
In particular, I'd like to get the size of the data I want to read, which is given at the beginning of my file by the variable "NumberOfPoints" in this piece of file
<VTKFile type="UnstructuredGrid" version="0.1" ><UnstructuredGrid><Piece NumberOfPoints="5101" NumberOfCells="10000"><Points>
Also, the data that I'd like to import in Matlab are preceded by
<DataArray type="Float64" Name="u" format="ascii">1.0000000000000000e+00 2.0000000000000000e+00
At the moment I can read them only if I put my data on a new line in the file, i.e.
<Piece NumberOfPoints>5101NumberOfCells="10000">
and
<DataArray type="Float64" Name="u" format="ascii">1.0000000000000000e+00 2.0000000000000000e+00
using this code
file = fopen( fileName, 'rt' );while (~feof( file )) str = fgets( file ); str = strtrim(str); switch (str) case '<Piece NumberOfPoints>' n = fscanf( file, '%d', 1 ) case '<DataArray type="Float64" Name="u" format="ascii">' val = fscanf( file, '%f', [1, n] )'; endendfclose( file );
How can I get the values without modifying my files by hand? I have a lot of files with very big size and this procedure takes long time.
Thank you,
Elisa
Best Answer