加速matlab运行的三重境界(3) reshape、squeeze、any、find、logical、prod、shiftdim、sub2ind、cums um、ind2sub、 ndgrid、repmat、sort、sum 等。 请注意matlan文档中还有这样一句补充:“Before taking the time to vectorize your code, read the section on Performance Acceleration. You may be able to speed up your program by just as much using the MATLAB JIT Accelera tor instead of vectorizing.”。何去何从,自己把握。 b、在必须使用多重循环时下,如果两个循环执行的次数不同,则在循环的外环执 行循环次数少的, 内环执行循环次数多的。这样可以显著提高速度。 2、a、预分配矩阵空间,即事先确定变量的大小,维数。这一类的函数有zeros、on es、cell、struct、 repmat等。 b、当要预分配一个非double型变量时使用repmat函数以加速,如将以下代码: A = int8(zeros(100)); 换成: A = repmat(int8(0), 100, 100); c、当需要扩充一个变量的大小、维数时使用repmat函数。