text

조회 수: 2 (최근 30일)
ricco
ricco 2011년 11월 17일
I have a matrix whixh i am converting to a .txt file, I need to include a header so that each column in the matrix can be defined when looking at the .txt file, how can this be done i.e. I need a different header for each column in the matrix, such as the first column is temp1, the second is temp2 and so on?
cheers
  댓글 수: 1
Jan
Jan 2011년 11월 17일
How do you convert the matrix to a txt file? What have you tried so far? Which problem did occur?

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

답변 (1개)

Jan
Jan 2011년 11월 17일
I do not understand the problem. Perhaps this helps:
Header = {'temp1', 'temp2', 'temp3'};
Data = rand(10, 3);
FID = fopen(fullfile(tempdir, 'test.txt'), 'w');
if FID == -1, error('Cannot open file'); end
fprintf(FID, '%-20s', Header{:});
fprintf(FID, '\n');
Fmt = [repmat('%-20g', 1, 3), '\n'];
fprintf(FID, Fmt, transpose(Data));
fclose(FID);
  댓글 수: 2
ricco
ricco 2011년 11월 17일
Basically what im trying to do is open a .txt file which has a header like you have shown above and the corresponsing data under each header. This .txt file is then loaded into another program where temp1 temp2 temp3 defines a paramater in the program, without being in this format the program will not work. The program is called lake analyzer2:
http://code.google.com/p/lakeanalyzer-2/downloads/detail?name=LakeAnalyzer3xUserManual.pdf
ricco
ricco 2011년 11월 17일
What you have shown does work in a sense, but in the .txt file the columns for Data do not lie under the specified header, the .txt file has 8 columns which im guessing it should have 3.

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by