Exporting a matrix tab separated

Hi, my name is Nahuel and I had a lot of troubles trying to export a 3 column matrix in a txt ASCII tab separated file with that form
500.000000 500.000000 5.000000
500.000000 500.000000 5.000000
500.000000 500.000000 5.000000
500.000000 500.000000 5.000000
It means tab column tab column tab... with 6 decimal numbers. I have tried with save and dlmwrite but the matlab hate's me :(

답변 (2개)

Walter Roberson
Walter Roberson 2012년 7월 15일

0 개 추천

Try dlmwrite() of your matrix, with delimiter set to '' (the empty string), and precision set to '\t%.6f'. I cannot promise that it will allow the precision to start with a tab.
If you did not need the leading tab, you would be more secure with delimiter set to '\t' and precision set to '%.6f'

댓글 수: 2

Nahuel
Nahuel 2012년 7월 15일
you say something like dlmwrite('myfile.txt', M, 'delimiter', '', 'precision', '\t%.6f')?? I need the leading tab
Walter Roberson
Walter Roberson 2012년 7월 16일
Yes, try that dlmwrite()

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

Jan
Jan 2012년 7월 16일

0 개 추천

Or directly without DLMWRITE:
X = rand(4, 3);
Fmt = [repmat('%.6f\t', 1, size(X, 2)), '\n'];
fid = fopen(FileName);
if fid == -1, error('Cannot open file'); end
fprintf(fid, Fmt, transpose(X));
fclose(fid);

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2012년 7월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by