Reputation: 111
Let's say T=1:20 ; P=[2 6 9 11 15 19]
.
How to write a logical value for P
in range T
?
The answer I want is: flag= [0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0]
.
Upvotes: 1
Views: 92
Reputation: 14939
For the fun of it, an alternative to Hoki's answer:
T(P) = 0;
flag = ~T
This sets all values that are in P equal to zero, and then checks if the values in T is 0 or not. This of course has the downside that it overwrites T
. Note: I would go for Hoki's answer!
Upvotes: 2
Reputation: 11812
You can define a logical vector flag
the size of T
, then use P
as an index vector of the flag to raise to true
:
T=1:20 ; P=[2 6 9 11 15 19] ;
flag = false(size(T)) ;
flag(P) = true ;
flag =
0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0
Upvotes: 4