readtable produces NaN values while reading a .txt file

5 views (last 30 days)
I am reading a text file using readtable:
opts = detectImportOptions('test.txt');
T = readtable('test.txt',opts);
The last line of the test.txt file is exactly as follows with a '%' sign at the beginning as follows:
%rate[1]:={0.0,46,87,47,807,842,42,.... up to 200 numbers}
But when I looked at T after reading the file, it says NaN for that particular variable:
{'%rate[1]:' } NaN
Is there a good way to tackle this?
  4 Comments
Guillaume
Guillaume on 26 Feb 2020
I should have said: attach a sample file that reproduces the problem. I don't get any NaN with your sample file.
Saying that, the format of the file doesn't appear suitable at all for readtable. You may be able to coerce readtable to read it correctly but it's not designed for this.
Chiranjib Dutta
Chiranjib Dutta on 26 Feb 2020
This is the file itself except I reduced the number of elements in the last line within brackets. For some reason, I could read the values where there is one single number but not the numbers with/within the brackets. I just wanted to use readtable (as readmatrix can not be used since there are various types of data - it complains) to make it a bit simple rather than writing few more lines of codes. I just needed few values and it worked fine for all of them except the last line. Anyways, I will park it for the time being now and thanks for your time. I really appreciate that.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!