error using readtable : Array indices must be positive integers or logical values.
이전 댓글 표시
Hi,
I have a simple tab-delimited file text which looks like :
Month H_Gh H_Dh H_Bn Ta
Jan 33 17 55 0.5
Feb 52 29 60 1.4
Mar 97 51 97 5.6
Apr 123 60 113 9.7
I want to create a table with readtable(filename) Matlab function. So I have tried this directly into console
T = readtable('data.txt', 'Delimiter', '\t')
Error using readtable (line 197)
Array indices must be positive integers or logical values.
Note: readtable detected the following parameters:
'HeaderLines', , 'ReadVariableNames', true, 'Format', ''
I have tried with others text files. If all rows in the file are the same types, readtable works well, but if a line contains string and numbers (like my file), this error pop. Anyone have an solution to propose ?
I'm on windows7 with R2018a.
댓글 수: 2
It works on this forum using your sample file:
T = readtable('simpleData.txt', 'Delimiter', '\t')
Arthur
2022년 8월 5일
답변 (1개)
Mathias Smeets
2022년 8월 4일
This seems to work:
opts = detectImportOptions('simpleData.txt');
tbl = readtable('simpleData.txt',opts);
I hope this is what you are asking :)
댓글 수: 7
Mathias Smeets
2022년 8월 5일
편집: Mathias Smeets
2022년 8월 5일
Try clearing your variables:
clear all
This might very maybe help
Arthur
2022년 8월 5일
Mathias Smeets
2022년 8월 5일
Are you sure there isn't some other function in your path that is called 'detectImportOptions' or something like that? Are you sure your code is calling the built in matlab function?
Arthur
2022년 8월 5일
Mathias Smeets
2022년 8월 5일
Very strange, I looked it up online and it seems like some people, as you can see here, solved some similar problems by reinstalling. But my suggestion would be to wait a bit until other people answer.
Sorry I can not help you further.
Arthur
2022년 8월 5일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!