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

Stephen23
Stephen23 2018년 6월 10일
편집: Stephen23 2018년 6월 10일
"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
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에 대해 자세히 알아보기

질문:

2018년 6월 9일

편집:

2018년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by