필터 지우기
필터 지우기

evaluating matrix in if statement

조회 수: 1 (최근 30일)
Franco
Franco 2011년 2월 11일
How can i get an if statement to evaluate a truth condition based on a matrix, such that
tol = [.0001;.0001;.0001;.0001;.0001;.0001;.0001;.0001;.0001;.0001]
difference_force = [10;10;10;10;10;10;10;10;10;10]
difference_displacement = [10;10;10;10;10;10;10;10;10;10]
if (difference_force > tol) == ones(1,10)' && (difference_displacement > tol)
without getting "Operands to the and && operators must be convertible to logical scalar values." error

채택된 답변

Walter Roberson
Walter Roberson 2011년 2월 11일
if all(difference_force > tol) && all(difference_displacement > tol)

추가 답변 (1개)

Oleg Komarov
Oleg Komarov 2011년 2월 11일
The condition:
if (difference_force > tol) & (difference_displacement > tol)
reads:
if every value of difference_force is elementwise bigger than its correspondent value in tol and at the same time every value of difference_displacement is elementwise bigger than its correspondent value in tol
Note that you cannot use shortcircuit operator (&&, ...) with vectors.
Oleg

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by