Checking values in a vector

조회 수: 3 (최근 30일)
Jose Grimaldo
Jose Grimaldo 2020년 2월 15일
편집: David Goodmanson 2020년 2월 16일
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

채택된 답변

David Goodmanson
David Goodmanson 2020년 2월 16일
편집: David Goodmanson 2020년 2월 16일
Hello Jose
if any(x(4:end)~=0)
(do something)
else
(do something else)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by