查看单个帖子
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 无法在Matlab中的while循环中添加条件

我有一个while循环,看起来像这样:

while ((min_t_border>0) && (colided_border_num > 0) && (~(min_t>0))) ... end 我想添加另一个条件: (exit_border_point ~= false)或(exit_border_point)当我将上述条件的以太放在if语句中时起作用。但是当我尝试将其添加为while的附加条件时,或者甚至当我尝试向if添加其他条件时,例如,我尝试过if ((exit_border_point ~= false) && (true))它告诉我:

“ ||和&&运算符的运算符必须可转换为逻辑标量值。”

我究竟做错了什么?

* exit_border_point获得以太(3x1)向量或为false



回答:

由于exit_border_point可以是向量,因此请尝试使用any或all函数,如下所示:

if (~any(exit_border_point)) 正如你可能已经猜到了, any返回true ,如果在阵列的计算结果为任何true和all返回true ,如果一切数组中是true 。它们有点像||向量等效项和&& 。



更多&回答...
poster 当前离线   回复时引用此帖