Nicer output from simulations

3 views (last 30 days)
DoVile Last Name:
DoVile Last Name: on 21 Sep 2012
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 Comment
tlawren
tlawren on 21 Sep 2012
Specifically, where do you want the output to go?

Sign in to comment.

Answers (2)

tlawren
tlawren on 21 Sep 2012
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 Comments
DoVile Last Name:
DoVile Last Name: on 21 Sep 2012
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 on 21 Sep 2012
I suggest you experiment with the horizontal tab: \t. It can help line up your columns.

Sign in to comment.


Ryan G
Ryan G on 26 Sep 2012
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.

Categories

Find more on Data Distribution Plots 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!