readtable error "Index exceeds array bounds." for Matlab 2018a
Show older comments
I recently installed Matlab 2018a on my Windows 7 pc after using Matlab 2017b. In order to read a simple text file without a file extension, which can be found in the attachments I used this line of code using the readtable function:
readtable([filename], 'CommentStyle', 'Q_cbl')
I added the 'CommentStyle', 'Q_cbl' because I want Matlab to ignore the couple of lines which start with Q_cbl
This worked well enough in Matlab 2017b, until I started using Matlab 2018a. From then on I got the following error message:
Error using readtable (line 197)
Index exceeds array bounds.
Note: readtable detected the following
parameters:
'Delimiter', '\t ',
'MultipleDelimsAsOne', true,
'ReadVariableNames', false, 'Format',
'%f%q%f%f%f%f%f%f'"
I tried several things as skipping the first line with the headers, using 'HeaderLines', ignoring the # symbol using 'TreatAsEmpty' and I checked the documentation of the function, but I cannot seem to find what has changed to cause this problem. I am planning to return to Matlab 2017b, but I am worried that this problem will reoccur in later versions of Matlab.
Could you help me find a solution to this problem, or is this maybe a bug of Matlab 2018?
Edit: added .zip file with the file I am trying to read
Accepted Answer
More Answers (1)
Harsh
on 20 Jul 2018
You can add a '.txt' extension to the file as 'initial_chem.txt' and then do the following in R2018a:
>> opts = detectImportOptions('initial_chem.txt');
>> opts.DataLines = [2,30];
>> readtable('initial_chem.txt',opts)
You can configure the importOptions (opts) properties to suit your workflow. For example, specifying the 'VariableTypes'.
Alternatively, you can also use the Import Tool (Import Data button) directly on the file without the extension (initial_chem) and generate a script. You can configure properties of your choosing before importing. For example, on this file, Import as a Delimited file with Column Delimiters as (Tab, Space) & Range as A2:H31.
1 Comment
Ruben Schulte
on 23 Jul 2018
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!