importdata skips the last few rows?

Hello all. I was using importdata in my code to bring in some matrices. I hadn't tested the code in quite some time, but I just upgraded from r2011a to r2012a and then ran it. Apparently importdata is now misbehaving. Whenever I try to do
>> data = importdata('file.txt')
where file.txt is a 360x720 ASCII file (generated from Matlab a while back using
>> save('file.txt','variable','-ASCII')
I get a variable that is 348x720:
>> size(data)
ans =
348 720
This happens with other 360x720 ASCII files as well, although for some of them I only get 347 rows. What do you think is going on? Thanks in advance!
PS: Here is a link to an example 'file.txt' this happens with.

댓글 수: 3

Sean de Wolski
Sean de Wolski 2012년 5월 9일
Does it fail in both 11a and 12a? Are there any empty lines or invisible ASCII that could be causing it to choke?
Sam
Sam 2012년 5월 9일
I deleted r2011a after installing r2012a so I can't be sure at this point, but I certainly never ran into this issue when using r2011a before.
Sam
Sam 2012년 5월 9일
Also, no, there are no empty lines or anything that I can see using a text editor.

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

 채택된 답변

Geoff
Geoff 2012년 5월 9일

2 개 추천

That's odd... Confirmed in my own 2012a.
It appears to be trimming all the entirely NaN rows from the end of your data.
I replaced line 348 with line 349, and confirmed the result is 347 rows long. Then I set the first element in line 360 to a non-nan value, and the result was 360 rows long.
I think this is stupid behaviour to have in a function, but nevermind.
Given that the files were created with save, you should do this instead:
data = load('file.txt', '-ASCII');

댓글 수: 4

Jan
Jan 2012년 5월 9일
LOAD('-ascii') is exactly what happens in 2009a:importdata. Is this function still an M-file in 2012a, which can be debugged?
Geoff
Geoff 2012년 5월 9일
In fact, I would submit a bug report to MathWorks on this issue if it indeed has been introduced in 2012a (can someone confirm in 2011a or 2011b?). There is no mention of this behaviour in the documentation.
I suspect that it might not be handling 'NaN' explicitly... It will simply give a NaN if the string is anything other than a number. So in that case, the last VALID input was on line 348, which contained numbers. Still... I would perceive that truncation as 'nannying'.
Geoff
Geoff 2012년 5월 9일
@Jan : Oh, I had a look and found this:
if ~isempty(numericData)
numericData = TrimTrailing(@(x)(isnan(x)), numericData);
end
Sam
Sam 2012년 5월 10일
Geoff, using "load" as you suggest does the trick. I will be submitting a bug report… I think that at the very least that behavior in "importdata" needs to be documented and optional. Thanks for your help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

Sam
2012년 5월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by