How to add header to a table?
Show older comments
Hello,
How can I add header to my table below ?
I want to add header
header={'Call price','Standard error','Number of paths'}
to the table.
S0=30;
K=32;
r=0.03;
sigma=0.2;
T=1;
n=365;
%m=500; % number of simulations
j=1;
for i=500:500:10000
[call_price,standard_error,numberOfpaths]=Call_Simulation(S0,K,r,sigma,n,i,T);
Call_Price(j)=call_price;
Standard_Error(j)=standard_error;
NumberOfPaths(j)=numberOfpaths;
j=j+1;
end
header={'Call price','Standard error','Number of paths'};
T=table(Call_Price',Standard_Error',NumberOfPaths');
disp(T);

Accepted Answer
More Answers (1)
Denise Selegato
on 24 Sep 2019
0 votes
Hi, I've been having a similar problem.
I want to put the following header on my table(T):
header = {'#DATA=RDC', 'PRIOR=GAUSS'}
However, if I try to use T.Properties.VariableNames, it gives me an error because I started my cell array with a "#". I need this # to be included in the header.
Is there a solution to my problem?
Thank you!
3 Comments
Star Strider
on 24 Sep 2019
Prior to R2019b, variable names in table objects have to be valid MATLAB variable names. Neither one in ‘header’ qualifies. You can certainly print those to a file as a separate line before you print your data (most likely using fprintf), then output your data to the file in a separate fprintf call.
However, if you upgrade to R2019b, you can likely do what you want. See the Release Notes, and specifically the writetable documentations section on: Write Tabular Data Containing Arbitrary Variable Names.
Note that this is also true for table objects in general. See: Specify Variable Names Using Any Characters in the R2019b table documentation.
Denise Selegato
on 25 Sep 2019
It worked perfctly on MATLAB2019b, thank you for helping.
Star Strider
on 25 Sep 2019
My pleasure.
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!