Problem with load function for ASCII files
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
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
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.)
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!