command to store array in file

20 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2011 年 12 月 3 日
is there one command in matlab store array in file?
thanks
  1 件のコメント
Chandra Kurniawan
Chandra Kurniawan 2011 年 12 月 3 日
Store into .MAT file??

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

回答 (1 件)

Jan
Jan 2011 年 12 月 3 日
As binary file:
X = rand(3, 4, 5);
save('FileName.mat', 'X');
As text file:
FID = fopen('FileName.txt', 'w');
if FID == -1, error('Cannot create file.'); end
fprintf(FID, '%g %g %g\n', X);
fclose(FID);
You find more examples in the documentation.
  4 件のコメント
Jan
Jan 2011 年 12 月 3 日
@huda nawaf: The saved file *is* properly, but your expectations are not matching. FPRINTF writes the elements columnwise, as expalined in the documentation repeatedly. If you want x appear as in the command window:
fprintf(FID, '%g %g %g %g %g\n', transpose(x));
Of course the format string '%g %g %g\n' is *not* thought for a [5x5] matrix.
huda nawaf
huda nawaf 2011 年 12 月 3 日
wonderful Knor
really thanks , and can read file by dlmread.
many many thanks

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

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by