4

Suppose I have a cell array containing an array of integer arrays. What is the best way to search the cell array for a specific array and return true if it exists and false otherwise?

1 Answer 1

5

You can use cellfun combined with isequal:

For example:

cellArr = {[1 2 3],'xcxc',magic(5),1:3};
element = [1 2 3];
indexes = cellfun( @(x)isequal(x,element),cellArr);

This will give you an array that contains true in the cells that the element exists. In order to check whether the element exists at least once, just use:

any(indexes)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.