Why dlmread do not work with dlmwrite?
2 views (last 30 days)
Show older comments
hi, I wrote symbols to file using dlmwrite, where the file became:
?,R,M,G,f,D,[],[]
W,E,R,R,T,U,H,K
N,D,F,[],[],[]
when tried to read it with dlmread , I got :
??? Error using ==> dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> ?,R,K
thanks
4 Comments
Walter Roberson
on 10 Dec 2011
As already explained, but I have expanded my answer to discuss this pointer further.
Answers (1)
Walter Roberson
on 10 Dec 2011
dlmread() can only read numeric data.
You have to cheat with dlmwrite() in order to write character data with it: it is not designed to write characters.
I did firmly say that I do not recommend that you use dlmwrite() to write character data, and that I only came up with the method to be contrary when someone said that it could not be done. I think I showed the code for the fopen / fprintf / fclose alternative.
[added]
When I said that dlmread can only read numeric data, I meant exactly that. It states this clearly in the documentation:
Tips
All data in the input file must be numeric. dlmread does not read files that contain nonnumeric data, even if the specified rows and columns contain only numeric data.
I have also examined the code that it uses; it uses an undocumented facility, but there is no doubt through testing that the facility will ONLY read numeric data.
0 Comments
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!