Three input statements in 'and function'

10 次查看(过去 30 天)
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.

回答(2 个)

Roger Stafford
Roger Stafford 2017-2-19
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 2017-2-19
编辑:dpb 2017-2-19
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by