![]() You also could consider adding the line y = zeros(size(t)) in the second function before the pieces are evaluated to avoid occasional memory reallocation in some cases (probably not costly in current Matlab version unless the function has many pieces and/or is called many times). It can be shown that any function written in a recursive manner can be rewritten. It is called very often because it goes within some. However, here's a solution similar to that of that uses logical indexing to avoid extra multiplication, addition, and also sets values outside of both ranges to NaN: function y = f(t) MATLAB functions need to have a defined value for the case where none of the conditions hold. In this section, you will see how to write recursive functions in Matlab. I have a small piecewise function that profiling reveals is taking 60 of the runtime of the program. You can always concatenate the data from your two functions before plotting.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |