필터 지우기
필터 지우기

example negation

조회 수: 6 (최근 30일)
Tor Fredrik Hove
Tor Fredrik Hove 2011년 10월 11일
Could someone give me an example for negation in matlab. I am a bit new and only know + - and stuff and not true false if else for example so if you use something aside from arithmetic basic operations could someone also explain thoose for the full understanding? Would have been so great! Thank you in advance!
Tor

채택된 답변

Wayne King
Wayne King 2011년 10월 11일
Hi Tor, welcome to MATLAB. You should spend some time reading the Getting Started Guide. Particularly, the section: Programming -> Flow Control
For example:
a = true; % a is a logical variable
if ~a
disp('Hi');
else
disp('Bye');
end
The above displays Bye because ~a is "not a" which is false, so the if statement evaluates to false and the else statment is evaluated.
MATLAB has countless variations on this theme:
X = randn(10,1);
if any(X) %check to see if there are any nonzero elements in X
disp('Hi');
else
disp('Bye');
end
any(X) is true and so Hi is displayed. Think for yourself when would ~any(X) be true? What would X have to be like?

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by