Why dlmread do not work with dlmwrite?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-12-10
As already explained, but I have expanded my answer to discuss this pointer further.
回答(1 个)
Walter Roberson
2011-12-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!