如何解决&&逻辑标量的操作数
在 matlab 中运行代码后,我遇到了这个错误,并且不确定如何解决它。我该如何解决这个问题。
警告:
|| 的操作数和&&运算符必须可转换为逻辑标量值。
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
After I run the code in matlab, I encounter this error and unsure how to solve it. How can I solve this problem.
Warning:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 dIx 和 dIy 是矩阵(与一维向量相反),则
max(dIx)
和max(dIy)
将返回向量。&&
和||
应该用于比较标量,而不是向量。您可能想要输入,
但我不能确定,因为我不知道代码应该做什么:)
If dIx and dIy are matrices (as opposed to 1-D vectors),
max(dIx)
andmax(dIy)
will return vectors.&&
and||
should be used to compare scalars, not vectors.You probably want to type
but I cannot tell for sure, as I dont know what the code is supposed to do :)
使用
&
和|
作为矩阵,而不是&&
、||
。&&
和||
是短路运算符。如果你仔细想想,它们对于矩阵来说毫无意义。例如,每当第一个参数为true
时,短路或 -||
就会停止并返回true
。但如何将其扩展到矩阵呢?
Use
&
and|
for matrixes instead of&&
,||
.&&
and||
are short circuit operators. If you think about it, they make no sense for matrixes. For example, the short circuit or -||
stops and returnstrue
whenever the first argument istrue
.But how would you extend that to a matrix?