How to Reduce Computation Time

조회 수: 13 (최근 30일)
Tez
Tez 2017년 8월 22일
편집: per isakson 2017년 8월 23일
Hello,
I am new to matlab. I am analyzing satellite data.each variable is about 400x31000 in dimension. After selecting data in those variable which i want i end up with a matrix of same dimension where data is in bunches , that is there will be data in some columns. i want the mean of these bunches separately.I wrote a code to do it but it takes more than 3 hours to run.I need help to reduce the time.
q=1;
nover1=NaN(size(nover));
nover2=NaN(size(nover));
nover3=NaN(size(nover));
meantime2=NaN(size(mean_ctime));
date2=NaN(size(date));
mlat1=NaN(size(mean_lat));
mlat2=NaN(size(mean_lat));
mlon1=NaN(size(mean_lon));
mlon2=NaN(size(mean_lon));
for i=1:size(alt,1);
for j=1:size(alt,2);
if alt(i,j)>80 && alt(i,j)<100;
if mean_lat(1,j)>0 && mean_lat(1,j)<20;
mlat1(1,j)=mean_lat(1,j);
mlon1(1,j)=mean_clon(1,j);
nover1(i,j)=nover(i,j);
meantime1(1,j)=mean_ctime(1,j);
date1(1,j)=date(1,j);
end
end
end
end
for j=1:size(alt,2);
if mean_clon(1,j)>60 && mean_clon(1,j)<120;
mlat2(1,j)=mlat1(1,j);
mlon2(1,j)=mlon1(1,j);
nover2(:,j)=nover1(:,j);
meantime2(1,j)=meantime1(1,j);
date2(1,j)=date1(1,j);
else
nover2(nover2==0)=NaN;
meantime2(meantime2==0)=NaN;
date2(date2==0)=NaN;
nno=nonzeros(nover2);
ntime=nonzeros(meantime2);
ndate=nonzeros(date2);
mno_42(1,q)=nanmean(nno); % the final no ver values
mtime_42(1,q)=nanmean(ntime); % the final time values
mdate_42(1,q)=nanmean(ndate); % the final date values
q=q+1;
nover2=NaN(size(nover));
meantime2=NaN(size(mean_time));
date2=NaN(size(date));
end
end
  댓글 수: 2
KSSV
KSSV 2017년 8월 22일
What form the satellite data is in?
Tez
Tez 2017년 8월 22일
netcdf files

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2017년 8월 22일
편집: per isakson 2017년 8월 23일
The code analyzer box in the upper right corner tells you that there is potential for improving the code. Hovering over the small bars in the right column will give you hints on how.
"preallocation for speed" see: Preallocation. That alone will work wonders on the speed of your code.
If that isn't enough see Profile to Improve Performance
Without being able to run the code it is difficult to be more specific than this.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by