MATLAB Answers

0

Write Data to Excel

Asked by nick12391 on 16 Jul 2019
Latest activity Answered by Walter Roberson
on 16 Jul 2019
I'm trying to output variables from my code to an Excel spreadsheet.
var = ['L_Chamber'; 'D_Chamber'; 'D_Throat '; 'L_Nozzle '; 'D_Nozzle '; 'Theta_N '];
val = [L_Chamber; D_Chamber; D_Throat; L_Nozzle; D_Exit; theta_n];
T = table(var,val);
filename = 'TCA_Dims.xlsx';
writetable(T',filename,'Sheet',1,'Range','A1')
This code works well, but I would like for the variable names, 'var', to be written to the top row, and their values, 'val', to be written to the second row. As it is, var and val are written to the first and second columns, respectively.

  0 Comments

Sign in to comment.

Products


Release

R2017a

3 Answers

Answer by nick12391 on 16 Jul 2019
 Accepted Answer

Nevermind, I figured it out:
Table = table(L_Chamber, D_Chamber, D_Throat, L_Nozzle, D_Exit, theta_n);
filename = 'TCA_Dims.xlsx';
writetable(Table,filename,'Sheet',1,'Range','A1')

  0 Comments

Sign in to comment.


KSSV
Answer by KSSV
on 16 Jul 2019

x = rand(3,1) ;
y = rand(3,1) ;
z = rand(3,1) ;
T = table(x,y,z) ;
writetable(T,'test.xlsx')

  0 Comments

Sign in to comment.


Walter Roberson
Answer by Walter Roberson
on 16 Jul 2019

T = table(cellstr(var).', val.');
writetable(T, filename, 'Sheet', 1, 'Range', 'A1', 'writevariablenames', false)

  0 Comments

Sign in to comment.