kurtkim
kurtkim

Reputation: 155

How to return the element in a vector satisfying some condition?(without 'if')

I want to get A'=[1 0 3 0]' from A=[1 10 3 100]' from the below MATLAB code

new_A=A(A<10)

But it does not work.

I need to do this without for or if.

Upvotes: 0

Views: 86

Answers (1)

matz
matz

Reputation: 656

(A < 10) is a binary matrix of the same size as A. Thus this should do the job:

A .* (A < 10)

Upvotes: 5

Related Questions