2

I have two arrays in Matlab say A = [1 4 89 2 67 247 2]
B = [0 1 1 1 0 0 1]

I want an array C, which contains elements from array A, if there is 1 in B at the corresponding index. In this case, C = [4 89 2 2].

How to do this?

4

1 に答える 1

5

論理インデックスを使用する:

>> C = A(logical(B))

C =

     4    89     2     2
于 2012-05-18T10:22:59.090 に答える