필터 지우기
필터 지우기

Using fprintf to store large square matrices

조회 수: 3 (최근 30일)
Joppy
Joppy 2018년 1월 1일
댓글: KSSV 2018년 1월 1일
So I've had trouble finding any information about this. Basically I need to store an M x M matrix to a file. I usually use the following to store data:
fname = fopen('data.dat', 'w');
fprintf(fname, '%d\n', mydata);
fclose(fname);
Which works for column/row vectors. But from the documentation I can only gather that to store a matrix I would need to have '%d %d ... %d\n' M times in the FORMAT specifier, which seems ridiculous?
I can make do by 'unpacking' the 1 x M^2 vector that the above code produces (when 'mydata' is an M x M matrix) but it seems unnecessary.
Thanks!

채택된 답변

KSSV
KSSV 2018년 1월 1일
A = rand(3) ;
fprintf([repmat('%f\t', 1, size(A, 2)) '\n'], A');
  댓글 수: 2
Joppy
Joppy 2018년 1월 1일
Thanks KSSV!
KSSV
KSSV 2018년 1월 1일
You are welcome...:)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by