Create Reverse Boolean Array in Matlab

I have a logical array isLand, it is true if the index is above the ground and false if the index is not above the ground, like the ocean. How can I easily create another isOcean boolean array which is an inLand inversion. Everything in isLand will be zeros in isOcean and vice versa.

I know I can do this using the for loop, but I feel that there is a much better way.

+3
source share
2 answers

Just use the logical NOT :

isOcean = ~isLand;

Easy febrile lemon juice !;)

+10
source

As gnowitz says, ~ (not an operator) is the correct answer, but you can also use

isOcean = isLand == 0;

This should work too:

isOcean = xor(1,isLand);

MATLAB .

+3

Source: https://habr.com/ru/post/1764745/


All Articles