Nicer output from simulations
2 次查看(过去 30 天)
显示 更早的评论
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 :)
回答(2 个)
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 个评论
Star Strider
2012-9-21
I suggest you experiment with the horizontal tab: \t. It can help line up your columns.
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!