field displacement array range

조회 수: 2 (최근 30일)
katarado
katarado 2017년 5월 19일
편집: katarado 2017년 6월 3일
Hello,
weather1618 and whether1623 are two 2D array of size 384x384. Following is my script section for weather1618Modified for which I tried to do a field displacement. If it helps, max_displ has a value of 139.7.
I do not get any error message when I run the script but I also don't get any value for bestDx and bestDy, the variables don't even create, What am I doing wrong?
%%Find Dx Dy for max_corr between two maps
maxCoeff=0;
weather1618Modified = zeros(384,384); %create weather array for time range
%weather1618Modified(:) = {NaN}; %Matlab cannot mix cell& double
for x = 1:384
for y = 1:384
for Dx = -max_displ:9: max_displ %139.7*2/30= 9 for a 30pixel appx.
for Dy = -max_displ:9: max_displ
%MAKE SURE x+Dy and y+DY don't exceed 1:384
if x+Dx<1 | y+Dy<1 | x+Dx>384 | y+Dy>384
continue
%weather1618Modified is the forecasted weather1823
weather1618Modified(x+Dx,y+Dy) = weather1618(x,y)
%Find the best correlation; Is corrcoef the right formula?
newCoeff=corrcoef(weather1623,weather1618Modified);
if newCoeff>maxCoeff
maxCoeff=newCoeff;
bestDx=Dx;
bestDy=Dy;
end
end
end
end
end
end
  댓글 수: 2
Jan
Jan 2017년 5월 19일
How could "x [...] not cross the interval 1 to 384", when it is created by "for x = 1:384"? I do not understand the question in consequence.
katarado
katarado 2017년 5월 19일
편집: katarado 2017년 5월 19일
x sould not go outside that inverval : It shoudn't be less than 1 and not more than 384. I am mostly asking for x+Dx and y+Dy (of the new array). It is now edited for clarity, thank you.

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

채택된 답변

Abhinav Gurram
Abhinav Gurram 2017년 5월 22일
From the code you have provided, it looks like the set of statements for setting 'maxCoeff', 'bestDx' and 'bestDy' is never reached. If you look closely, the MATLAB Code Analyzer mentions that the line:
weather1618Modified(x+Dx,y+Dy) = weather1618(x,y)
and possibly the following lines, cannot be reached. This is because these statements are placed after the 'continue' and therefore, never get executed. To know more about how to use continue, please visit: Continue documentation - with examples
Another thing to keep in mind is that when 'continue' is used within nested loops, it only skips the remaining statements in the body of the loop in which it occurs. Therefore, you might want to consider enclosing these set of statements in an 'else' condition.
Hope this helps!
  댓글 수: 2
katarado
katarado 2017년 6월 3일
편집: katarado 2017년 6월 3일
thank you for your answer! I tried both using an else statement and putting the "end" directly under the "continue" line but it does not work
katarado
katarado 2017년 6월 3일
also, where and how can I use the MATLAB Code Analyzer?

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

추가 답변 (1개)

Jan
Jan 2017년 5월 22일
The continue statement prevents the code from creating any variables.
for Dy = -max_displ:9: max_displ
if x+Dx<1 | y+Dy<1 | x+Dx>384 | y+Dy>384
continue
x = 0
end
end
Here x=0 is not reached, because the continue forwards the execution directly to the next iteration. I assume you simply want to omit this command.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by