Removing automatic variable names in array2table or writetable and adding some text to the header of output file

조회 수: 14 (최근 30일)
Hi, I am trying to get a text output file using the following code:
Output=[DD,D];
T=array2table(Output);
writetable(T,'m.txt','Delimiter',' ')
I get the variable names Output1 and Output2 as headers in the output text file. I would like to remove both names and instead have a text like DR as the heading.
  댓글 수: 5
Mohammad R. Ghassemi
Mohammad R. Ghassemi 2021년 10월 17일
Again the solution gives:
DR_1 DR_2
169 30
178 26
234 26
I found a way to remove the variable names: 'WriteVariableNames',false in writetable handles.
What I need now is to add a DR to start of the text file.
Mohammad R. Ghassemi
Mohammad R. Ghassemi 2021년 10월 17일
Finally I found that fprintf is a better fuction for my purpose:
fid=fopen('m1.txt', 'w'); % open a file for writing
fprintf(fid,'DR\n'); % print a title
fprintf(fid,'%d %d\n',Output); % print values in column order % two values appear on each row of the file
fclose(fid);
Thanks all.

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

답변 (1개)

dpb
dpb 2021년 10월 17일
As @Ive J points out, define variable names as desired. NB there's no need for intermediate variables here, either--if you already have the variables, then just use them directly:
T=table(DD,D,'VariableNames',{'DR1','DR2'});

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by