Error in reading dat file in matlab installed on linux using textread (Error using fullfile)
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm reading a dat file using textread.
the code works fine on the Matlab in windows, but shows an error in linux:
[a,b,c,d,e,g,h,i] = textread(input_file,'%s%s%d%d%f%f%f%f%*f%*f%*f%*f','delimiter',',');
the error is as bellow:
Error using fullfile (line 51)
String input not supported.
Error in textread (line 151)
if (noargname(@exist,varargin{1}) ~= 2 || noargname(@exist,fullfile(cd,varargin{1})) ~= 2)
changing "textread" to "txtscan" might solve the problem (didn't try) but then I have to change the number of output args which requires more changes in the following lines.
The version of Matlab on Windows is R2014a and on Linux: 20107a.
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 5월 19일
However your input_file has been constructed, it has changed from character vector before to string object now. In particular in R2017a, importdata() imports strings as string objects instead of as character vectors.
However, in each case that I have been able to think of in which you might have had your datatype silently change from a character vector to a string object, your previous data type would have been cell array of character vector. For example,
T = array2table({'foo';'bar'}, 'variablenames',{'hello'});
T2 = array2table({"foo";"bar"}, 'variablenames',{'hello'});
if the tables had been generated with readtable() then the data type of T2.hello(2) might have changed to string object, but before T1.hello(2) would be cell array containing character vector, not character vector itself. So if you got a string into input_file now, then unless you changed code yourself, the previous datatype would have had to have been cell array of character vector, and that would not be accepted by textread() as its first argument. So I am suspicious that nothing else has been changed.
In any case, the work around, which will work in both releases, is to use
[a,b,c,d,e,g,h,i] = textread(char(input_file), '%s%s%d%d%f%f%f%f%*f%*f%*f%*f','delimiter',',');
This will work whether input_file turns out to be a character vector, or a cell array entry containing a character vector, or a string object.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!