Nicer output from simulations

조회 수: 2 (최근 30일)
DoVile Last Name:
DoVile Last Name: 2012년 9월 21일
I am taking a Monte-Carlo course and so i have some output, the homework is all done but i would like to make the end product a bit nicer. At the moment my output looks like:
ans =
CMC: Mean of 0.9512 with 95% C.I: 0.8815 1.0210
ans =
Control variate: Mean of 0.9482 with 95% C.I: 0.89261.0038
ans =
Alpha = -2.2307. Rho = 0.6042. W_hat = 0.0932. True W = 0.0919
But what i would like it to look like is something more along the lines of a top row with "Method Mean LowerCI UpperCI" and then 2 lines under with the needed values. And if possible a line under that where instead of alpha there is an actual alpha symbol.
If anyone has some examples or suggestions it would be a big help :)
  댓글 수: 1
tlawren
tlawren 2012년 9월 21일
Specifically, where do you want the output to go?

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

답변 (2개)

tlawren
tlawren 2012년 9월 21일
Where do you want to the output to go? The command window, a file, or somewhere else?
Something like the following could work to get the formatted output to the command window. It's not elegant, but it does the trick.
hline = sprintf('MM LCI UCI\n'); % header line
dline1 = sprintf('%d %d %d\n', mm1, lci1, uc1); % date line 1
dline2 = sprintf('%d %d %d\n', mm2, lci2, uc2); % data line 2
disp([hline,dline1,dline2]); % display to command window
Look up sprintf and fprintf online for more information.
  댓글 수: 2
DoVile Last Name:
DoVile Last Name: 2012년 9월 21일
I do indeed want it to output to the command window, and using a few modifications from your code
hline = sprintf('%s %s %s %s\n', 'Method', 'Mean', 'LowerCI', 'UpperCI');
dline1 = sprintf('%s %s %s %s\n', 'CMC',sprintf('%0.4f',mean(vOptionValuesControlVariate)), sprintf('%0.4f',CI(1)), sprintf('%0.4f',CI(2))); % date line 1
dline2 = sprintf('%s %s %s %s\n', 'CV ',sprintf('%0.4f',estMeanCallAA), sprintf('%0.4f',CI2(1)), sprintf('%0.4f',CI2(2))); % data line 2
dline3 = sprintf('%s %s %s %s %s %s %s\n' ,['Alpha = ' sprintf('%0.4f',alfa), '. Rho = ', sprintf('%0.4f',rho), '. W_hat = ', sprintf('%0.4f',estMeanCallGA), '. True W = ', sprintf('%0.4f',trueMeanCallGA)]);
disp([hline,dline1,dline2,dline3]);
I got a much nicer output, however i still cant get the columns alligned. Ie. i want Method, CMC and CV to be alligned vertically. How can i achieve this ?
Thank you
Star Strider
Star Strider 2012년 9월 21일
I suggest you experiment with the horizontal tab: \t. It can help line up your columns.

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


Ryan G
Ryan G 2012년 9월 26일
You may be interested in disp instead of sprintf (depending on application, see this answer. sprintf is far and away a much more powerful and flexible utility, but disp is a bit more easy to use and may help you see the issues that you have.
There are examples of monte carlo simulation that show how disp can be used. Not necessarily directly applying to the way you may want to use it, though.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by