data type on matlab performance

1 回表示 (過去 30 日間)
Likun
Likun 2013 年 12 月 3 日
Hi all,
I am analyzing the performance of my code using profile. Here is part of my code:
global NX1 NX2 LU_nr dx1 dx2 u1 u2 strain du11 du12 du21 du22 index;
j=1:1:LU_nr ;
%left
idx1=(rem(j,NX1)==1);
idx2=(rem(j,NX1)==0);
idx3=(~(idx1|idx2));
index(idx1)=LU_nr+(j(idx1)-1)/NX1+1;
du11(idx1)=(u1(j(idx1)+1)-u1(index(idx1)))/(2.*dx1);
du21(idx1)=(u2(j(idx1)+1)-u2(index(idx1)))/(2.*dx1);
%right
index(idx2)=LU_nr+NX2+j(idx2)/NX1;
du11(idx2)=(u1(index(idx2))-u1(j(idx2)-1))/(2.*dx1);
du21(idx2)=(u2(index(idx2))-u2(j(idx2)-1))/(2.*dx1);
%middle
du11(idx3)=(u1(j(idx3)+1)-u1(j(idx3)-1))/(2.*dx1);
du21(idx3)=(u2(j(idx3)+1)-u2(j(idx3)-1))/(2.*dx1);
I found that the global variables on line 1 cost more than half time. I have defined the variables in the main function and use them in this subroutine. Can anyone suggest a more efficient way? Thank you.

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by