0
votes

I have a 435x1 cell array whose elements are either 'y', 'n', or '?'. I want to find which indices are equal to 'y'.

With normal arrays, I just use the find function. But I can't use that with cell arrays because eq is not defined for type cell.

I think I can go through each element and do

for index=1:size(cell_array,1)
    if cell_array{index} == 'y'
        %add index to some array of indices
    end
end

But is there a vectorized way to go through the array and find indices contain elements that are equal to 'y'? Any help is appreciated.

1
@EitanT - I think Sterling was most interested in the [cell_array{:}]=='y' bit, which was not a possible solution for the other question, so find could be used in the familiar way with eq. It's much the same functionally, I'll admit. - chappjc

1 Answers

5
votes

Since you know each cell will contain a single character you can concatenate all the cell elements and do a single vectorized test:

find([cell_array{:}]=='y')

Possibly the most straightforward way is just to use strcmp, which can accept a cell array as the second argument:

find(strcmp('y',cell_array))