Three input statements in 'and function'
11 views (last 30 days)
Show older comments
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.
0 Comments
Answers (2)
Roger Stafford
on 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;
0 Comments
dpb
on 19 Feb 2017
Edited: dpb
on 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.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!