필터 지우기
필터 지우기

parfor nested for loops

조회 수: 3 (최근 30일)
Eb Bed
Eb Bed 2018년 8월 21일
댓글: OCDER 2018년 8월 22일
The following script works finely in for loop, but I need to implement parfor to speed up. I am looking for help how to implement parfor in the following nested for loop. Many thanks for your kind help.
Z_anom = zeros(n,m);
d = 0;
for y = 1:n
for c_day = 1:m
d = d + 1;
g = 0; % counter for the grid point
for i = 1:nlat
for j = 1:nlon
g = g + 1;
Z_anom(d,g) = (Z(c_day,y,i,j) - Z5(c_day,i,j))*sqrt(cosd(datalat(i)));
end
end
end
end
  댓글 수: 6
Eb Bed
Eb Bed 2018년 8월 21일
Dear OCDER it is not missed. Y is year c_day is day of the season and z5 is averaged over the year then subtract from z to get anomoloud
OCDER
OCDER 2018년 8월 22일
Hm, something isn't adding up.
Z_anom = zero(n, m);
for y = 1:n
for c_day = 1:m
d = d+1;
...
Z_anom(d, g) = ...
end
end
This means size of Z_anom will [n*m, nlat*nlon], and NOT [m, n] as you started out with.
Also, datalat size is [80, 80], but it seems you are accessing i from 1:nlat, where nlat = 80?
Please provide the size of all variable as per my 1st comment.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by