Writing matrix to .dat file

조회 수: 46 (최근 30일)
K Dani
K Dani 2018년 8월 29일
댓글: K Dani 2018년 8월 29일
I need to write two sets of data to a .dat file. I have two row vectors, n and an. The index n needs to be written to the value of an. When I attempt this, though, I get all of the n values first and then the an values when I need them in two columns. Here's what I tried.
% Transforming vectors into column vector formatting
n = 0:50;
n = n'
% Creating matrix to be called and written to .dat
mat = [n,an];
%%Exporting data to .dat
% Creating file to be written to
fileName = fopen('mat.dat','w');
% Writing data to file
fprintf(fileName, '%f %f\n', mat);
% Closing
fclose(fileName)
%Opening file to read
type mat.dat
I'm not too familiar with this so I'm sure I'm missing something crucial.

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 29일
fprintf(fileName, '%f %f\n', mat.');
This is due to the fact that MATLAB accesses data "down" the columns first.
  댓글 수: 1
K Dani
K Dani 2018년 8월 29일
Ah of course! Thank you so much!

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

추가 답변 (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