Click here to load reader

怎样提高 matlab 的效率

  • View
    124

  • Download
    0

Embed Size (px)

DESCRIPTION

怎样提高 matlab 的效率. 王睿智 2011 年 4 月 15 日. 作业总结. 总结一. 一维矩阵代替多维矩阵 多维矩阵的 访问要比一 维矩阵要 慢,比如 bwlabel 里要记录每列的包的编号、开始行号、结束行号、所在列号、所在组号,如果使用五个 1 * n 的矩阵要比使用一个 5 * n 的矩阵要快近 4 近四倍。. 总结二. 给数组或矩阵预分配内存 特别是使用大型数组或矩阵时, Matlab 进行动态内存分配和取消时,可能会产生内存碎片,这将导致大量闲置内存产生,预分配可通过提前给大型数据结构预约足够空间来避免这个问题。 . 总结三. - PowerPoint PPT Presentation

Text of 怎样提高 matlab 的效率

PowerPoint

matlab2011415bwlabel1*n5*n4

MatlabMATLABMatlabMatlabbwlabelcall by referenceMatlabMforwhile

i=0;for n = 0:0.1:1000i=i+1;y(i)=cos(n)endn= 0:0.1:1000;y=cos(n);

1000000 x 1 u 1000000 x 1 vvi= ui+ 1

matlab cfortranbuild-in functionfunction y = fm(x) y = x + 1;

for i = 1 : n v(i) = fm(u(i)); endm-file [email protected]/C++C#delegate

fh = @fm;for i = 1 : nv(i) = fh(u(i)); endfunction handleanonymous functionLISP, Pythonlambda

fa = @(x) x + 1; for i = 1 : nv(i) = fa(u(i)); endanonymous functioninline function

fi = inline('x + 1', 'x'); for i = 1 : n v(i) = fi(u(i)); endinline functionfeval

v(i) = feval_r('fm', u(i)); v(i) = feval_r(fh, u(i)); v(i) = feval_r(fa, u(i));fevalm-function0.385 secfunction handle0.615 secanonymous function0.635 secinline function166.00 secfeval_r('fm', u(i))8.328 secfeval_r(fh, u(i))0.618 secfeval_r(fa, u(i))0.652 secfeval_r(@fm, u(i))2.788 secfeval_r(@fa, u(i))34.689 secm-functionfunction handleanonymous functionm-inline functionmatlabparse

feval_r(@fm, u(i)) > feval_r(fh, u(i))@fmfeval_r('fm', u(i)) > feval_r(fh, u(i)) Matlabbuild-in functionm-file functionfunction handleanonymous functionarray-indexA(i):cell-index:C{i};struct field:S.fieldnamestruct field (dynamic):S.('fieldname')matlabMATLABcellcell array>> a={'matlab',20;ones(2,3),1:10}

a =

'matlab'[20][2x3 double][1x10 double]cell arrayA(i) for a numeric array0.0052 secC{i} for a cell array0.2568 secstruct field0.0045 secstruct field (with dynamic name)1.0394 secMATLABstruct fieldcell array40050MATLAB200OOobject-orientedobjectMATLABOOobjects

Search related