Importing a numeric data text file with missing data
Afficher commentaires plus anciens
Hi
I am trying to load multiple files onto matlab . The files contain the results of nonlinear dynamic analysis on a structure. So they are in the form of a matrix with multiple rows and columns. Due to convergence problem or so, some of the analyses were terminated earlier that they complete and as a result some of the output files are not complete. It means there are some empty elements which is on the last row essentially.
I am trying load these files but unfortunately , matlab gets me an error due to those files with missing data. I am using the load command to import the files .
Is there any way that I can import those files , I am happy with zeroes to be placed where the data are missing too.
Thanks Reza.
11 commentaires
Star Strider
le 3 Oct 2015
Attach one of the problem files to your original Question. (Use the ‘paperclip’ icon, and complete both the ‘Choose file’ and ‘Attach file’ steps.)
Reza
le 3 Oct 2015
Star Strider
le 3 Oct 2015
I have no idea how to read that. What application wrote it? Can you export it in another format?
The problem is that it’s a series of run-together numbers with no structure I can recognise. MATLAB does not have field-specific file reading (FORTRAN does), so it has to be in a format MATLAB can work with.
Please upload your data as an original text file, or in some other standard format, such as an Excel file.
Reza
le 3 Oct 2015
Star Strider
le 3 Oct 2015
That isn’t the format of the ‘Sample’ file. The one you posted in your comment would be relatively easy to read and work with.
Reza
le 3 Oct 2015
per isakson
le 4 Oct 2015
Modifié(e) : per isakson
le 4 Oct 2015
With data from Sample.zip. Does this solve it?
fid = fopen( 'C:\tmp\Long_col_drift_4000619.out' );
cac = textscan( fid, '%f%f', 'Collectoutput', true );
fclose( fid );
num = cac{:};
num( end-3:end, : )
it outputs
ans =
103.0350 -0.0004
103.0400 -0.0004
103.0450 -0.0004
103.0500 NaN
the missing data is indicated with NaN
per isakson
le 4 Oct 2015
Modifié(e) : per isakson
le 4 Oct 2015
"120 column instead of just 2"   Replace %f%f by repmat('%f',[1,120])
"zero instead of NAN?"   num(isnan(num))=0;   or add   'EmptyValue',0   to textscan
Reza
le 4 Oct 2015
Réponses (0)
Catégories
En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!