load -ascii : inconsistent behavior

2 vues (au cours des 30 derniers jours)
Hal Caswell
Hal Caswell le 10 Déc 2012
I am trying to read a tab-delimited ascii file. It has 99 rows and 5 columns.
In R2012b, the command
load FILENAME.ext -ascii
correctly loads the file, producing a variable FILENAME of size 99 x 5.
On a different machine, with R2012a, the same command applied to the same file produces a variable FILENAME of size 1 x 495.
That is, under R2012a the load command is reading the file as a single line of values, rather than as a 2-dimensional array. Strangely, if I use the Import Wizard in R2012a, it immediately recognizes FILENAME as containing a 99 x 5 array of tab-delimited values.
I need to have this code work under both versions of Matlab. Any explanations for the inconsistent behavior?
FWIW the code also worked under earlier versions.
Thanks. Hal

Réponse acceptée

Jan
Jan le 10 Déc 2012
Modifié(e) : Jan le 10 Déc 2012
Read ASCII files with LOAD had a bug in 2012a, when the old MacOS-9 linebreaks are used. Then load the file using fileread, replace char(13) by char(10) and save the resulting string with fopen + fwrite.
  1 commentaire
Hal Caswell
Hal Caswell le 10 Déc 2012
Thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 10 Déc 2012
Try dlmread() or importdata() instead.
  1 commentaire
Hal Caswell
Hal Caswell le 10 Déc 2012
It looks like those would indeed work, and would be fine if I was just starting out. But I've used load -ascii for a long time and would prefer to not have to change the command any time I go back to use older code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by