How to correctly use dlmread to read a large matrix in m-file?

3 ビュー (過去 30 日間)
Yu-Yun
Yu-Yun 2013 年 11 月 13 日
コメント済み: dpb 2013 年 11 月 14 日
I saved a 11-by-100001 matrix as a m-file with dlmwrite. Then I read the m-file with dlmread, but the matrix in Matlab became a column vector that had the length of 11*100001=1100011.
How can I correctly read the matrix back in Matlab? My Matlab version is 7.10.0. Thank you!
If you would like to see how the error happens, try the following code:
M = rand(11,100001);
dlmwrite('matrix_m.m',M)
LM = dlmread('matrix_m.m');
You'll see LM in workspace is a 1100011x1 column vector.
  6 件のコメント
Yu-Yun
Yu-Yun 2013 年 11 月 14 日
編集済み: Yu-Yun 2013 年 11 月 14 日
I used .m as the extension because I didn't know .csv is better for saving matrix. :P
I just tried .csv. Unfortunately, it doesn't work for Matlab 7.10.0. I think I should start using save to save my data. Anyway, thanks a lot for the help!
dpb
dpb 2013 年 11 月 14 日
In Matlab, the 'm-file' is the storage for source files -- naming data files with the extension makes them visible to the parser as if they were source files so, amongst other unexpected results is that you could cause failure of a function or script by aliasing a real function of the same name.
Specifically what caused the difference here is unclear to me as it didn't occur this morning when I tried to document a case to send to TMW as a bug report.
I got the one-column "solution" on both cases -- peculiar, indeed.
I did look at the two files on disk--they're identical and do have the newline character after the rows so ML should be able to determine the shape from the data and other than the namesearch problem above the file extension should not have any bearing.
It's a bug IMO, whether TMW will think it serious-enough given the length of the record to take under consideration I don't know.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by