2014-01-14 49 views
1

我是新來的matlab和matlab給出的錯誤'下標索引必須是真正的正整數或邏輯'在代碼段的最後一行(如果顯示< 0.01 || rank(A'* A)〜= 2)下面,請指導我這個:Matlab錯誤'下標索引必須是真正的正整數或邏輯。'

function [u,v] = optical_flow(im1,im2,windowSize) 
x_c=im1(1:end-1,2:end)-im2(1:end-1,1:end-1);%(define rows 1~479,2~639 columns)-(rows 1~479,1~639) 
y_c=im2(2:end,1:end-1)-im1(1:end-1,1:end-1); 
t_c=im2(1:end-1,1:end-1)-im1(1:end-1,1:end-1); 
%initialize for speed 
u = zeros(size(x_c)); 
v = u; 
for x = 1:size(x_c,1)-windowSize %fpr all x 
    for y = 1:size(x_c,2)-windowSize 
     %Get the windows of the dimensions 
     win_x=imcrop(x_c,[x y windowSize windowSize]); 
     win_y=imcrop(y_c,[x y windowSize windowSize]); 
     win_t=imcrop(t_c,[x y windowSize windowSize]); 
     %Convert windows to vectors to produce A for solving later 
     A = [win_x(:) win_y(:)]; 
     %Compute threshold t (smallest eigenvalue of A'A) 
     th=min(eig(A'*A)); 
     %Optical flow is only valid in regions with t<0.01 and 
     rank =2; 
     %if true, then it should not be computed 
     if th<0.01 || rank(A'*A)~=2 

回答

3

您分配一個值rank,這意味着現在MATLAB對待rank作爲變量。當您嘗試計算rank(A'*A)時,您以後將rank作爲函數處理。你應該重命名你的rank變量。

%Optical flow is only valid in regions with t<0.01 and 
    rank =2; % <--- RENAME THIS 
    %if true, then it should not be computed 
相關問題