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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by