What is the correct file extension for function "importdata" working properly?
이전 댓글 표시
Hello, Recently I am running a script in which it imports a data text file "result.rpt" into a cell array by function "importdata". The script run perfectly some time ago when it was compiled (before R2013), but fails this time on the version R2014b. It only generates an empty array. But when I rename the file to "result.dat", the "importdata" can function properly.
E.g.,
The file "result.rpt" contains:
HEAD LINE 1
HEAD LINE 2
NAME-A 1 2 3 4
NAME-B 5 6 7 8
And if I type in:
[a,b,c]=importdata('result.rpt', ' ', 2)
it will create:
a = []
b = []
c = []
And,
The file "result.dat" contains:
HEAD LINE 1
HEAD LINE 2
NAME-A 1 2 3 4
NAME-B 5 6 7 8
And if I type in:
[a,b,c]=importdata('result.dat', ' ', 2)
it will create:
a =
data: [2x4 double]
textdata: {4x1 cell}
b =
c = 2
Therefore, I would like to ask if there is any limitation about the function "importdata" on file extensions after R2014b? Is the function changed to a limited range of extension and refuses to read in other type of files?
Thanks a lot!!
Yaoguang
답변 (2개)
dpb
2015년 7월 30일
0 개 추천
If this is indeed reproducible and can be absolutely confirmed to be the file name extension only, it's a bug. Submit a bug report to TMW at www.mathworks.com
documents nothing re: '.rpt' as a special file extension for latest version.
I'm sure TMW will tell you the workaround is to temporarily rename the file if it is, indeed, so(*) for the time being.
(*) And I'm not saying it isn't, just saying if by any remote chance there is something else going on you haven't quite recognized yet...
Walter Roberson
2015년 7월 30일
0 개 추천
If you read between the lines there, noticing that "any" file extension is supported for audioread and VideoReader, you can see that multiple attempts are going to be made to load the file using helper functions; if one of those helper functions does not error out and instead returns empty then you would get the result you observe.
댓글 수: 1
dpb
2015년 7월 30일
I've not dug thru the logic internal to importdata but seems like TMW must've changed the search order or something to see different behavior.
It's that nebulous operation and excessive overhead as opposed to just opening the specific file that's always made me stay away from these generic functions albeit I understand TMW's desire for the convenience of trying to make it so the user doesn't need to know anything.
Not sure there's any foolproof method altho giving up and returning with empty if haven't yet tried simple ASCII doesn't sound like "the right stuff" solution.
카테고리
도움말 센터 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!