Reading complicated mixed text/numbers file
古いコメントを表示
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>
5101
NumberOfCells="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] )';
end
end
fclose( 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
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!