MATLAB Answers

0

Find function for cell array

Asked by Anupam Saikia on 7 May 2019
Latest activity Commented on by Anupam Saikia on 16 May 2019
Accepted Answer by Jan
I havr a cell myCell 1x200 Each cell contains set of three values like myCell{1,1} = 1,118,180 ... myCell{1,8}= 1,122,185 and so on If I have to use find function by providing all three values, how should I use?

  0 Comments

Sign in to comment.

2 Answers

Answer by Jan
on 7 May 2019
Edited by Jan
on 7 May 2019
 Accepted Answer

Do all elemts of the cell have the same size and type? Then working with a numerical array is easier and faster:
M = cat(1, myCell{:});
match = find(ismember(M, [1,2,128], 'rows'))
% or
find(M == [1,2,128]) % auto-expanding, >=Matlab R2016b

  1 Comment

Thank you so much.

Sign in to comment.


Answer by Adam
on 7 May 2019

wantedArray = [1,122,185];
cellfun( @(x) isequal(x,wantedArray), myCell );
You would be better off using a numeric array though for neatly structured data.

  1 Comment

Thank you so much.

Sign in to comment.