What is the alternative for function tril(n), which is executed without using loops??

Answers (1)

Without any context for your use, it is impossible to suggest methods to vectorize your code. As Adam mentioned, tril itself does not inherently need a loop. If you need to loop through q=tril(ones(n)) and do things with it, you can generally speed up that loop with cellfun.

1 Comment

cellfun is actually slower than an equivalent for loop in most cases, though where it is important a proper speed test using timeit is useful. I like cellfun and arrayfun for code neatness (though some find a for loop neater), but for speed unfortunately they are not fast unlike using boost or std for_each or transform operations in C++

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 9 Mar 2017

Commented:

on 9 Mar 2017

Community Treasure Hunt

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

Start Hunting!