Program vs Function?
显示 更早的评论
Hi, I would just like to ask what is the difference between writing a program vs a function? I'm currently working on a few cdf exercises for my course: for example, prob that returns lies within 1% and 9% given that: no of monte carlo simulations: 1,000,000, mu = 6% and sigma = 25%. Now, I'm able to generate the answer by doing either: prob_bet_1and9=sum((return_norm>.01)&(return_norm<.09))/n or prob_bet_1and9F=normcdf(.09,.06,.25)-normcdf(.01,.06,.25) but I'm told this is not a function. How do I make this a function and what's the difference between that and what I'm doing right now? Why is one better than the other? FYI, I'm still a newbie in Matlab so if you can explain it plainly that would be amazing. Thanks!
1 个评论
"Program vs Function?"
I know what a function is, but what is a program? Can you please show a reference for MATLAB.
"How do I make this a function and what's the difference between that and what I'm doing right now?"
回答(1 个)
Walter Roberson
2018-6-10
0 个投票
functions are almost always better.
Not mentioned in the page I linked to is the fact that MATLAB can almost always generate more efficient code for a function than it can for a script.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!