Three input statements in 'and function'

11 Ansichten (letzte 30 Tage)
loes visser
loes visser am 19 Feb. 2017
Bearbeitet: dpb am 19 Feb. 2017
I'm now using the code;
a(not(and(CLO < 1, ACT < 1))) = -4;
to make all other data of a where CLO and ACT are less then 1, -4. But I like to implement another boundery, but
a(not(and(CLO < 1, ACT >= 1, ACT <5))) = -4;
does not work. What is the correct form to execute this action?
ACT, CLO and a are [18x26] vectors.

Antworten (2)

Roger Stafford
Roger Stafford am 19 Feb. 2017
It would either be:
a(~(CLO<1&ACT>=1&ACT<5)) = -4;
or if you were determined to use the ‘not’ and ‘and’ forms,
a(not(and(and(CLO<1,ACT>=1),ACT<5))) = -4;

dpb
dpb am 19 Feb. 2017
Bearbeitet: dpb am 19 Feb. 2017
Let's use operators instead of functions and associating parentheses to make easier to keep things straight..
I almost always start by writing the logical explicitly first...
ix=(CLO<1) & (ACT>=1 & ACT <5);
a(~ix) = -4;
I may then paste the expression into the addressing paren's but often will keep it for resulting simpler-to-read expression. The 'puter won't care, but my poor eyes do when start trying to debug or read code some time later...
You can, of course, always use the functional for and but it as you discovered is two inputs at a time so have to nest...
and(c,and(a,b))
etc., etc. which gets even more convoluted so the operators are a great simplifier here.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by