Matlab错误“下标索引必须是实数正整数或逻辑". [英] Matlab error 'Subscript indices must either be real positive integers or logicals.'

查看:288
本文介绍了Matlab错误“下标索引必须是实数正整数或逻辑".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是matlab的新手,matlab在代码段的最后一行给出错误下标索引必须是实数或逻辑"(如果th <0.01 || rank(A'* A)〜= 2)如下所示,请对此进行指导:

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

推荐答案

您为rank分配了一个值,这意味着MATLAB现在将rank视为变量.稍后,当您尝试计算rank(A'*A)时,会将rank视为函数.您应该重命名rank变量.

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

这篇关于Matlab错误“下标索引必须是实数正整数或逻辑".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆