MATLAB Answers

How to find a set of data in a cell?

조회 수: 1(최근 30일)
kyana shayan
kyana shayan 3 Feb 2016
Hi every one, I need to find a set of data such as [1 2] in a cell consists of C=([1 2 3],[4 5],[5 6 7]). I don't need the indexes as the outputs. A true/false output is just fine. I tried to use find function, but it turned out to me it doesn't work for a set of data. Thanks.

답변(1개)

Stephen Cobeldick
Stephen Cobeldick 3 Feb 2016
편집: Stephen Cobeldick 3 Feb 2016
The function strfind is very handy for matching a sequence of values:
>> C = {[1 2 3],[4 5],[5 6 7]};
>> X = [1,2];
>> cellfun(@(v)~isempty(strfind(v,X)),C)
ans =
1 0 0

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by