2014-10-19 2 views
1

열의 값은 51과 50이지만, 그 이상의 값을 사용할 때 대기 행렬은 인덱스가 그것의 큰 이미지와 거기에 맞지 않을 바운드 예외, 그래서 MATLAB dosent waitbar 또는 아무것도 사용하여 닫았습니다. 오류가 발생하면 matlab을 종료하는 방법이 필요합니다.Matlab은 이미지 바운드 예외가있을 때 대기 표시기의 십자 기호를 사용하여 종료합니다.

h = waitbar(0,'Progress','Name','Calculating Feature Heights...',... 
     'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); 
setappdata(h,'canceling',0); %initiallizes waitbar 
s1 = size(A); 
s2 = size(B); 

if (s1(1) < s2(1)) 
    n = s1(1); 
else 
    n = s2(1); % ensures that bounds of i are within the bounds of both images 
end 
for i = 21:1:n % sets bounds for rows 

if getappdata(h,'canceling') %checks for user pushing the cancel button on the waitbar 
    break 
end 
waitbar(i/(n-1),h)  %progress bar 
    for j = 61:1:(m-60) % sets bounds for columns 
     if A(i,j) == A(i,j-1) %if adjacent pixels are the same, 
      Z(i,j) = Z(i,j-1); %they have the same height 
      disp(i,j) = disp(i,j-l); 
     elseif A((i), j) == B(i, j) && A(i,j) ~= A(i,j-1) && A(i,j-1) == B(i,j-1) 
      Z(i,j) = Z0; %condiions for pixels/features in the 'focal plane' 
      disp(i,j) = 0; 
     else 
      for l = 1:1:20 %sets scan range in rows for disparity 
       for k = 1:1:60 %sets disparity scan range in cols 
        if (A(i,j) == B(i-l, j-k) && B(i-l, j-k-1) == B(i-l, j-k)) 
         Z(i,j) = Z(i-l,(j-k-1)); %allows for multipixel features 
         disp(i,j) = disp(i-l,(j-k-1)); 
         break 
        elseif (A(i, j) == B(i-l, j-k) && B(i-l, j-k-1) ~= B(i-l, j-k)) 
         xA = [i j]; 
         xB = [i-l j-k]; 
         d = xB-xA; 
         Z(i,j) = Z0 - (fl*shift)/sqrt((d(1)^2)+(d(2)^2)); 
         disp(i,j) = sqrt((d(1)^2)+(d(2)^2)); 
         break 
        elseif (A(i,j) == B(i-l, j+k) && B(i-l, j+k-1) == B(i-l, j+k)) 
         Z(i,j) = Z(i-l,(j+k-1)); 
         disp(i,j) = disp(i-l,(j+k-1)); 
         break 
        elseif (A(i, j) == B(i-l, j+k) && B(i-l, j+k-1) ~= B(i-l, j+k)) 
         xA = [i j]; 
         xB = [i-l j+k]; 
         d = xB-xA; 
         Z(i,j) = Z0 - (fl*shift)/sqrt((d(1)^2)+(d(2)^2)); 
         disp(i,j) = sqrt((d(1)^2)+(d(2)^2)); 
         break 

        else 
         continue 
        end 
       end 
      end 
     end 
    end 
end 
delete(h) 

답변

0

try/catch 블록을 사용하십시오.

try 
    % whatever that might error 
catch 
    delete(h) 
end 
+0

"j = 61 : 1 : (m-60)"오류입니다. 값을 초과하면 51:50으로 고정되고 어떤 수단 으로든 고정 해제되지 않습니다. 그래서이 문제를 제거 할 필요가있다 – CLearner

+0

@CLearner for 루프 **를 둘러싼 try catch 블록을 사용하면 문제가 없다. 시도 해봐. – chappjc