2017-05-29 33 views
0

これは私が持っているスクリプトです。それは------分離まで働く。私はMatlabから何のエラーもありませんが、どちらもbestDxやbestDyの返品を受けません。助けてください。 (最初の部分がちょうど文脈であなたを置くために与えられている)matlab complex forループ相関計算

%% 
% Variables after running script Read_eA3_file.m 
%date_time_UTC 
%reflectivity 
%clutter_mask 

%Convert units 
dBZ = reflectivity * 0.375 - 30; 
dBZ_Mask = clutter_mask * 0.375 - 30; 

%Replace clutter values with NaN 
weather = NaN(size(dBZ)); %initialise to constant 
weather(dBZ>=dBZ_Mask) = dBZ(dBZ>=dBZ_Mask); %copy values when A >= B 

%Reduce to range -- those are 384x384 arrays 
dBZ_range = dBZ(:,:,1:16); %16:18 to 16:23 included 
weather_range = weather(:,:,1:16); %16:18 to 16:23 included 
weather1618 = weather(:,:,1); %16:18 map only 
weather1623 = weather(:,:,16); %16:23 map only 

% Plot maps 
image(imrotate(-weather1618,90)); %of 16:18 
image(imrotate(-weather1623,90)); %of 16:23 

%Find x,y of strongest dBZ 
%Since the value are all negative. I look for their minimun 
[M,I] = min(weather1618(:)); %for 16:18 
[I_row, I_col] = ind2sub(size(weather1618),I); %values are 255 and 143 
[M2,I2] = min(weather1623(:)); %for 16:23 
[I2_row, I2_col] = ind2sub(size(weather1623),I2); %values are 223 and 7 

%Calc displacement 
%I get a value of 139.7140 
max_displ=sqrt((I2_row-I_row)^2+(I2_col-I_col)^2); %between 1618 and 1623 

%% 
% -----Section below does not work; ONLY RUN the section ABOVE--------- 

%% 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 
     %30 pixel appx. 
     for Dx = -max_displ:30: max_displ 
      for Dy = -max_displ:30: max_displ 

       %Limit range of x+Dx and y+Dy to 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 


%% Calc displacement 
bestDispl = sqrt(bestDx^2+bestDy^2); %bestDispl for a 5 min frame 

%Calc speed 
speed = bestDispl/time; 
+2

:*「(?なぜ、このコードは動作していない」)、デバッグの助けを求める質問は、」必要な動作、特定の問題やエラーして再生するために必要な最短のコードを含める必要があります。それは質問そのものです。明確な問題文がない質問は他の読者には役に立たない」* – Wolfie

+0

matlabデバッガを使って、変数が決して設定されない理由を理解してください。 – m7913d

答えて

0

次の場合は最初の後にcontinue文を削除(または他のどこかに置く)しなければなりません。

continueステートメントは、forループの残りの部分をスキップし、次の繰り返しに進みます。したがって、bestDxとbestDyは決して設定されません。

文書:ガイドラインからhttps://se.mathworks.com/help/matlab/ref/continue.html