readtable error "Index exceeds array bounds." for Matlab 2018a

조회 수: 1 (최근 30일)
Ruben Schulte
Ruben Schulte 2018년 7월 13일
댓글: Ruben Schulte 2018년 7월 23일
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

채택된 답변

Ruben Schulte
Ruben Schulte 2018년 7월 23일
The problem was solved thanks to the quick response of Liam from Mathworks support.
He suggested the following:
opts = detectImportOptions('initial_chem','FileType','text',...
'CommentStyle',' ');
opts.VariableTypes = {'char','char','char','char', ...
'double','double','double', 'double'};
t = readtable('initial_chem',opts);
I added his full solution with comments in the attachments in case anyone else comes acros this issue

추가 답변 (1개)

Harsh
Harsh 2018년 7월 20일
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
Ruben Schulte
Ruben Schulte 2018년 7월 23일
Thanks for your suggestion!
Unfortunately, Matlab did not recognize my file when I add the .txt extension. As a result, the problem was not solved. I do like the DataLines option. I looked for that option earlier, but could not find it before.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by