如何解决逻辑标量的操作数 [英] How to solve && operands to logical scalar

查看:87
本文介绍了如何解决逻辑标量的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在matlab中运行代码后,遇到此错误,不确定如何解决.我该如何解决这个问题.

After I run the code in matlab, I encounter this error and unsure how to solve it. How can I solve this problem.

警告:

||的运算符和&&运算符必须可以转换为逻辑标量值.

Operands to the || and && operators must be convertible to logical scalar values.

    Jgray = double(rgb2gray(J));
    % Calculate the Gradients
    [dIx, dIy] = gradient(Jgray);
    if max(dIx)<=103 && max(dIy)<=100
        B =  abs(dIy) - abs(dIx);
    else
        B = abs(dIx) - abs(dIy);
    end

推荐答案

如果dIx和dIy是矩阵(与一维向量相反),则 max(dIx) max(dIy) 将返回向量.

If dIx and dIy are matrices (as opposed to 1-D vectors), max(dIx) and max(dIy) will return vectors.

&& || 应该用于比较标量,而不是向量.

&& and || should be used to compare scalars, not vectors.

可能要输入

if max(dIx(:))<=103 && max(dIy(:))<=100

但是我不确定,因为我不知道代码应该做什么:)

but I cannot tell for sure, as I dont know what the code is supposed to do :)

这篇关于如何解决逻辑标量的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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