help loading ascii files in 2012a that worked in previous versions

1 次查看(过去 30 天)
I have common delimited ascii files (output as either .txt or .csv files from excel). There are 7 header lines with "%" as the first character and the data section is square. These files load fine under 2010, 2008, 2007 versions of matlab.
With Version 2012a
1. load filename.txt (or .csv) produces no error and an empty file.
2. importdata (filename) produces a character cell array (including the header lines).
3. importdata (filename,',',7) reads into a character array only the first 7 header lines (even though the documentation says it should read numeric data after the headerlines, it reads only the headerlines).
4. [A delim headerlines] = importdata(filename) produces the complete cell array (including all headerlines), a "," delimiter and lists ALL the lines as headerlines. At the bottom is an example txt file that shows the problem.
It appears that importdata AND load are now looking for "%" to appear anywhere on a line (not just the first character) - and treating the entire line as a comment/header if one is found.
I have other files that have file names like AMO.data.txt That are ascii files with header lines and square data (with space delimiters - no commas).
load AMO.data.txt works ok - but the array name that it defaults to is now AMO_data, while in previous versions it was AMO (i.e. the default name of the variable was up to the first ".". The new version now replaces all "." with "_" until it finds a file delimiter it recognizes.
These two issues is going to require a massive amount of code modifications (or throwing out very useful comment information!)
Suggestions?
------- Example: with no blank lines in the file....
%% Legend:
1,10,,,,,,,,,,,% test
1,10,,,,,,,,,,,% test

回答(1 个)

per isakson
per isakson 2012-8-26
编辑:per isakson 2012-8-26
I run R2012a, 64bit, Windows7.
load(..) seems to read the numerical data ok.
>> load('cssm.poi.txt' )
>> cssm_poi
cssm_poi =
1 10
1 10
where cssm.poi.txt contains
%%Legend:
1,10,,,,,,,,,,,% test
1,10,,,,,,,,,,,% test
There is the alternative syntax
data = load(...);
and, but ...
eval( [ variable_name, '= load(', file_name, ');' ] )
.
AFAIK: importdata(...) cannot handle the on-line comments. The documentation doesn't say it can. That might have been an undocumented feature.
.
You write "require a massive amount of code modifications". The question seems to be how the code can be updated to R2012a with minimal modifications. I know too little about the code to say how.
  1. The "massive amount of code modifications" does that affect the code that writes or reads the data-files? Or both?
  2. textscan can read the example data. Are the number of columns known?
In toolboxes and in the File Exchange there are many functions that read text files.

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by