Problem with load function for ASCII files

7 visualizaciones (últimos 30 días)
Norm Nelson
Norm Nelson el 20 de Jun. de 2012
Hi,
I'm unable to load some ASCII files in R2012a. I can open the file in the editor and confirm it's formatted properly (rectangular array of floating point numbers, comments at top of file begun with '%'), so it's not a problem with permissions. When I try to load() the files it returns empty values.
the files look like this, roughly:
% temp.txt
81 0.3 2.364483884 0.075 0.045 0 0 2
81 0.3 2.389637968 0.075 0.045 0 0 2
81 0.3 2.739698969 0.075 0.045 0 0 2
81 0.3 2.662140543 0.075 0.045 0 0 2
...
This is a transcript of me trying to load the file and confirm it's loaded.
>> load temp.txt
>> whos
Name Size Bytes Class Attributes
temp 0x0 0 double
>>
There are no error messages, as you can see, just returning an empty matrix. No idea how to proceed from here.
  5 comentarios
Norm Nelson
Norm Nelson el 20 de Jun. de 2012
Also, these files opened just fine in R2008 ... !
Norm Nelson
Norm Nelson el 20 de Jun. de 2012
Unfortunately, this will require me to revise a large number of scripts that currently use load() to load ascii files. Why doesn't load() work for these files any more, I guess is my real question. Thanks!

Iniciar sesión para comentar.

Respuesta aceptada

Norm Nelson
Norm Nelson el 20 de Jun. de 2012
importdata() works best: reads the files correctly without me having to edit the files. Thanks, per.
I'm baffled as to why MATLAB's behavior has changed with regards to something as fundamental as load(). This will mean a huge amount of work to correct. Oh well.
  1 comentario
per isakson
per isakson el 23 de Jun. de 2012
Is it really the comment line, which causes the failed read?

Iniciar sesión para comentar.

Más respuestas (1)

per isakson
per isakson el 20 de Jun. de 2012
Did you try
dlmread
Read ASCII-delimited file of numeric data into matrix
.
--- Cont. ---
I cannot make dlmread handle comment lines - regardless of how I set the range.
.
--- Revisit the OP's question ---
I find it difficult to remember all the details of all the functions, which read ascii-data. When faced with a failed read it is too easy to jump into the wrong conclusions. I need a "selection guide". Nevermind, I copy&pasted the five lines of OP into cssm.txt and cssm.mat. The two files are thus identical but for the extension. Then I run (R2012a, 64bit, Windows7)
load cssm.txt % ok
load cssm.mat % error
load cssm.mat -ascii % ok
importdata cssm.txt % ok
importdata cssm.mat % error
.
load cssm.mat caused the error message
Error using load
Unable to read MAT-file h:\m\cssm\cssm.mat: not a binary MAT-file.
Try LOAD -ASCII to read as text.
and importdata cssm.mat caused the warning
Warning: File contains uninterpretable data.
> In importdata at 144
and returned an empty result
ans =
data: []
textdata: {}
Yes, I have checked twice that the correct data is assign in the "ok-cases".
Thus, I believe there is some other problem with the file of OP.
  2 comentarios
Norm Nelson
Norm Nelson el 20 de Jun. de 2012
yes, this works, if I strip the comments from the file
Walter Roberson
Walter Roberson el 20 de Jun. de 2012
dlmread() has an option to specify range.
You could put your own load() routine earlier in the path. Or you could do a batch edit to change load to your own routine name (a safer approach.)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by