MATLAB Answers

Checking values in a vector

2 views (last 30 days)
Im trying to check a vector, that after the third integer the rest of the values should be equal to zero. If there is value that is not equal to zero, I should end the program. Im trying to do it without using loops.
I try doing this but it does not check the values. What can I Do?
x=[5 9 0 0 0 01]
if x(4:end)~=0
error('Invalid values entered. Program Terminated');
end

  0 Comments

Sign in to comment.

Accepted Answer

David Goodmanson
David Goodmanson on 16 Feb 2020
Edited: David Goodmanson on 16 Feb 2020
Hello Jose
if any(x(4:end)~=0)
(do something)
else
(do something else)
end

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.