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);
error_table.PNG

 채택된 답변

Star Strider
Star Strider 2019년 2월 17일

2 개 추천

Use the 'VariableNames' (link) name-value pair with your ‘header’ cell array.

댓글 수: 5

Bai chen
Bai chen 2019년 2월 17일
I looked through the link.
It does not help.
The elements of ‘header’ must be valid MATLAB variable names. Then it works.
Try this:
T = table(rand(5,1),rand(5,1),rand(5,1))
header={'Call_price','Standard_error','Number_of_paths'};
T.Properties.VariableNames = header
producing:
T =
5×3 table
Var1 Var2 Var3
_______ _______ ________
0.48861 0.54681 0.67914
0.57853 0.52114 0.39552
0.23728 0.23159 0.36744
0.45885 0.4889 0.98798
0.96309 0.62406 0.037739
T =
5×3 table
Call_price Standard_error Number_of_paths
__________ ______________ _______________
0.48861 0.54681 0.67914
0.57853 0.52114 0.39552
0.23728 0.23159 0.36744
0.45885 0.4889 0.98798
0.96309 0.62406 0.037739
That should do what you want.
Walter Roberson
Walter Roberson 2019년 2월 17일
Note that table() objects do not support arbitrary column headers. They can store VariableDescription for each column, but summary() is about the only thing that displays the description.
Shannon Wagoner
Shannon Wagoner 2020년 3월 4일
@walter can you shhow an example of summary?
Star Strider
Star Strider 2020년 3월 4일

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Denise Selegato
Denise Selegato 2019년 9월 24일

0 개 추천

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

Star Strider
Star Strider 2019년 9월 24일
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
Denise Selegato 2019년 9월 25일
It worked perfctly on MATLAB2019b, thank you for helping.
Star Strider
Star Strider 2019년 9월 25일
My pleasure.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2019년 2월 17일

댓글:

2020년 3월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by