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

回答(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 个评论

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++

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

评论:

2017-3-9

Community Treasure Hunt

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

Start Hunting!

Translated by