1

I am new to matlab and matlab gives error 'Subscript indices must either be real positive integers or logicals'at the last line of the code segment ( if th<0.01 || rank(A'*A)~=2) shown below, please guide me for this:

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
MrAzzaman
  • 4,734
  • 12
  • 25
wajid
  • 37
  • 2
  • 10

1 Answers1

3

You assign a value to rank, which means that MATLAB now treats rank as a variable. You later treat rank as a function when you try to calculate rank(A'*A). You should rename your rank variable.

    %Optical flow is only valid in regions with t<0.01 and
    rank =2; % <--- RENAME THIS
    %if true, then it should not be computed
MrAzzaman
  • 4,734
  • 12
  • 25