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

2 views (last 30 days)
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')

Accepted Answer

Mathieu NOE
Mathieu NOE on 16 Mar 2022
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");

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!