概述
来自matlab 2011b的帮助文件,有时间会翻译一下。
Vectorizing Loops
The MATLAB software uses a matrix language, which means it is designed for vector and matrix operations. You can often speed up your code by using vectorizing algorithms that take advantage of this design. Vectorization means converting for and while loops
to equivalent vector or matrix operations.
Simple Example of Vectorizing
Here is one way to compute the sine of 1001 values ranging from 0 to 10:
i = 0;
for t = 0:.01:10
i = i + 1;
y(i) = sin(t);
end
A vectorized version of the same code is
t = 0:.01:10;
y = sin(t);
The second example executes much faster than the first and is the way MATLAB is meant to be used. Test this on your system by creating scripts that contain the code shown, and then using the tic and toc functions to measure the perf
最后
以上就是拉长电话为你收集整理的matlab中怎么将for向量化,matlab中的循环向量化 | 学步园的全部内容,希望文章能够帮你解决matlab中怎么将for向量化,matlab中的循环向量化 | 学步园所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复