How to export 1 column of data with variable names on separate lines

조회 수: 2 (최근 30일)
My main problem, is that I am using the 'table' and 'writetable' commands, however I would like the exported text file to not all be on one line but me more along the lines of whats shown below
Odd_term1 value
Odd_term2 value
etc...
whereas at the moment it looks like this
Odd_term1,Oddterm2,
value,value
etc....
below is the lines of code I am using to try and achieve this, thanks in advance for any help.
T = table(data.PresiOddterms, 'VariableNames', {'Odd_terms'})
writetable(T, 'resistor_data')

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 3월 16일
hello
this demo to flip a (vertical) 5 (variables) x 3 (values) table to hor direction
now the saved data (in txt file) is like :
Var1 0.644318130193692 0.378609382660268 0.811580458282477
Var2 0.532825588799455 0.350727103576883 0.939001561999887
Var3 0.875942811492984 0.550156342898422 0.622475086001227
Var4 0.587044704531417 0.207742292733028 0.301246330279491
Var5 0.470923348517591 0.230488160211558 0.844308792695389
T = array2table(rand(3,5));
VariableNames = (T.Properties.VariableNames)';
data = (table2cell(T))';
% flip directions of table to output txt file
Out = [VariableNames data];
writecell(Out,'savefile.txt',"Delimiter","tab");

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by