Matlab中的逻辑掩码 [英] Logical mask in Matlab
本文介绍了Matlab中的逻辑掩码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用逻辑数组掩码对这个数组的所有值进行平方a = [1:1:2000}.逻辑阵列掩码定义为b = a< 500. 我该如何使用遮罩对这些值求平方?
I am trying to use a logical array mask to square all the values of this array a = [1:1:2000}. The logical array mask is defined as b = a <500. How would I square those values using the mask?
推荐答案
a = 1:2000; %# 1 by 2000 double
b = a<500; %# 1 by 2000 logical
a_squared = a(b).^2; %# 1 by 499 double
%# logical index--^ ^-- 'dot' means element-wise operation
这篇关于Matlab中的逻辑掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文