来自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中的循环向量化内容请搜索靠谱客的其他文章。
发表评论 取消回复