Create and save a table

19 views (last 30 days)
How can i create and save a table from a multiple result of a function?
I used this command to print result on a file.dat
fprintf(fid1,' _______________________________________________________________________ \n');
fprintf(fid1,'r(m) b(r,t)(m) P(r,t)(Pa) r^2/t (m^2/s) Sw\n');
fprintf(fid1,' ________________________________________________________________ \n');
fprintf(fid1,'%15.2f %15.6f %15.6e %15.6e %12.4f\n',r,b_r,P,Sim,S_w)
and I've something like this
________________________________________________________________________
r(m) b(r,t)(m) P(r,t)(Pa) r^2/t (m^2/s) Sw
________________________________________________________________________
0.30 70.000000 2.068816e+07 2.853881e-09 0.3000
0.60 70.000000 2.060942e+07 1.141553e-08 0.3000
0.90 70.000000 2.056336e+07 2.568493e-08 0.3000
.... ........ ........ ........ ......
but i want the same result on a table .xls (for example) or .mat
Thanks for your help.

Accepted Answer

Cris LaPierre
Cris LaPierre on 17 Nov 2021
Since you already have the variables defined, I would create a variable of data type table.
varnames = ["r(m)" "b(r,t)(m)" "P(r,t)(Pa)" "r^2/t (m^2/s)" "Sw"];
r = [0.3 0.6 0.9]';
b_r = [70 70 70]';
P = [2.068816e7 2.060942e7 2.056336e7]';
Sim = [2.853881e-9 1.141553e-8 2.568493e-8]';
S_w = [.3 .3 .3]';
% create a table
T = table(r,b_r,P,Sim,S_w,'VariableNames',varnames)
T = 3×5 table
r(m) b(r,t)(m) P(r,t)(Pa) r^2/t (m^2/s) Sw ____ _________ __________ _____________ ___ 0.3 70 2.0688e+07 2.8539e-09 0.3 0.6 70 2.0609e+07 1.1416e-08 0.3 0.9 70 2.0563e+07 2.5685e-08 0.3
I could then write this table to an xlsx file using writetable.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!