user3261573
user3261573

Reputation: 89

How to filter cell arrays in Matlab?

I want to filter the following cell array in Matlab:

A =

[1x3 double]    [3]    [5]    [6]
[1x3 double]    [3]    [4]    [5]
[1x3 double]    [6]    [7]    [8]

How can filter out only the rows where the value in column 3 is larger than 4? As a result it should then give me rows 1 and 3.

Thanks a lot for your help!

Upvotes: 1

Views: 1028

Answers (1)

houtanb
houtanb

Reputation: 4100

You can simply do the comparison and then select the returned rows out of A:

A([A{:,3}]>4, :);

In the above,

[A{:,3}]>4

yields

 1 0 1

showing which rows have a third column greater than 4. Choosing these rows out of A gives you the answer you want. (Updated after @LuisMendo's comment)

Upvotes: 1

Related Questions