- in matlab you don't need to enclose an if condition in (). Personally, I find that wrapping if condition in () make the code harder to read.
- Never end an if on an elseif. The code you wrote would error (with "output response not assigned") if p is anything other than the scalar 1 or 2. At least my code (which ends with an else not an elseif) will return 'no'.
- Use a better name for your function and write comment. Writing code that can be understood by others is just as important as writing code that works.
2 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/509843-how-to-make-a-response-for-more-than-one-period#comment_807305
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/509843-how-to-make-a-response-for-more-than-one-period#comment_807305
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/509843-how-to-make-a-response-for-more-than-one-period#comment_807322
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/509843-how-to-make-a-response-for-more-than-one-period#comment_807322
Sign in to comment.