我是靠谱客的博主 拉长电话,最近开发中收集的这篇文章主要介绍matlab中怎么将for向量化,matlab中的循环向量化 | 学步园,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

来自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中的循环向量化 | 学步园所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部