Amndeep7
Amndeep7

Reputation: 2091

What is the source of an apparent argument mismatch in a while loop?

This is from the same project as Why is a function parameter considered an undefined variable?. In this case, I have a vector of balls from which I am acquiring a velocity vector (of length 3) whose values I am squaring and then summing. For some reason, it thinks that the following code results in a comma separated list that does not have just one value, where if I run each bit piecemeal, it works just fine.

>> while sum(balls.velocity.^2) ~= 0
end
 comma separated list must have exactly one item.

>> sum(balls.velocity.^2) ~= 0

ans =

     1

>> while ans
end
>> %had to CTRL+C in order to exit the infinite loop

How do I make the while loop understand that it is only receiving one value?

Upvotes: 0

Views: 34

Answers (1)

Daniel
Daniel

Reputation: 36710

I can't explain why, but this solves the issue:

while sum([balls.velocity].^2) ~= 0,end

Upvotes: 2

Related Questions