dlmwrite with two row header

조회 수: 4 (최근 30일)
Orkun OZENER
Orkun OZENER 2014년 1월 1일
댓글: Orkun OZENER 2014년 1월 1일
Hi, I am trying to use dlm write with two row header.(Datanames and headers) I made it for one row header. But For additional header it did not work? I could not write the second row header I would be pleased for any help.
% the data
fnam='stop3.txt'; % <data file
hdr={'Var_no','Acc','Dcc','Vcrs','Fcs','Vmax','Sure'}; % First header
hdr2={'No','m/s2','m/s2','km/h','kg', 'm/s','s'}; % Second Header
m=magic(7) %data
% the engine
txt=sprintf('%s\t %s\r\t',hdr{:},hdr2{:});
txt(end)='';
dlmwrite(fnam,txt,'');
dlmwrite(fnam,m,'-append','delimiter','\t');
% the result
type(fnam)
The first row is ok. Bur for secodn row..It did not work. The data should be formatted like this as tab delimited txt file.
Var_No Acc Dcc VCrs FCs Vmax sure
No m/s2 m/s2 km/h kg m/s s
64 1,4 -2 40 0,145529778 11,46442127 50
50 1,2 -2 40 0,15172966 11,46151161 61
57 1,3 -2 40 0,151792581 11,49402332 60
36 1 -2 40 0,15426373 11,43154716 61
Kind Regards. Orkun ÖZENER

채택된 답변

Jan
Jan 2014년 1월 1일
편집: Jan 2014년 1월 1일
The creation of txt does not do, what you expect. Simply check the contents of this string:
disp(txt)
Suggestion:
fmt = repmat('%s\t ', 1, length(hdr));
fmt(end:end+1) = '\n';
txt = sprintf(fmt, hdr{:},hdr2{:});
But then dlmwrite inserts an additional line break after the header. What about:
fmt = repmat('%s\t ', 1, length(hdr));
fmt(end:end+1) = '\n';
fid = fopen(fnam, 'w');
fprintf(fid, fmt, hdr{:});
fprintf(fid, fmt, hdr2{:});
fclose(fid);
dlmwrite(fnam,m,'-append','delimiter','\t');
Why struggeling with the high-level and smart dlmwrite when you can write to the file directly?
  댓글 수: 1
Orkun OZENER
Orkun OZENER 2014년 1월 1일
Dear Jan Simon,
Thanks for your answer, It fully worked. I tried it step by step. And then I understand the ('\n') addition. AT last it is working now.
For your last question. Actually the program (AVL CONCERTO) that I postprocess needs tab delimited txt for importing. So while searching for this I found dlmwrite. I did not tried or I did not now the basic way.. ıf there is and if you have time I would be happy to hear. Kind Regards. And also happy new year.
I did not tried the basic writ

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by