Importing a numeric data text file with missing data

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 件のコメント

Star Strider
Star Strider 2015 年 10 月 3 日
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
Reza 2015 年 10 月 3 日
I just attached a sample ! Any suggestions would be much appreciated !
Star Strider
Star Strider 2015 年 10 月 3 日
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
Reza 2015 年 10 月 3 日
Here is a sample excel file see the attachment please
it's like an m*n matrix with some of the elements missing in the last row
Star Strider
Star Strider 2015 年 10 月 3 日
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
Reza 2015 年 10 月 3 日
Just show me how to load the excel file (It's originally in a text file though) i sent u into matlab with that missing element and replace the empty array with 0
per isakson
per isakson 2015 年 10 月 4 日
編集済み: per isakson 2015 年 10 月 4 日
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
Reza
Reza 2015 年 10 月 4 日
編集済み: Reza 2015 年 10 月 4 日
Perfect this solved my problem.
Just one more question .
Now assume I have multiple files (All in the same directory) that I'd like to read (e.g Long_col_drift_4000619.out, Long_col_drift_4000620.out,Long_col_drift_4000621.out.....) and apply this code to them , what change should i make to the code u posted?
Another difference is that the matrix has now 120 column instead of just 2, then how can I adjust the number of %f%f%f.... accordingly ?
My other question is that How can I put zero instead of NAN?
Your help is much appreciated !
per isakson
per isakson 2015 年 10 月 4 日
編集済み: per isakson 2015 年 10 月 4 日
"120 column instead of just 2" &nbsp Replace %f%f by repmat('%f',[1,120])
"zero instead of NAN?" &nbsp num(isnan(num))=0; &nbsp or add &nbsp 'EmptyValue',0 &nbsp to textscan
"multiple files" &nbsp See sequence of files
Reza
Reza 2015 年 10 月 4 日
thanks so much
I am still struggling to import multiple files even when I read that url. Could u clarify a bit? It's unclear for me to apply it within the little code u shared with me.
Thanks

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

タグ

タグが未入力です。

質問済み:

2015 年 10 月 3 日

コメント済み:

2015 年 10 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by