# find all elements (cells) of a single element (cell) in cell array

11 views (last 30 days)
MA on 28 Aug 2019
Commented: MA on 28 Aug 2019
I have the following cell array (c) which is 3*2. Now I want to find all elements of lets say c{1,1} which is [3,2]. The answer that I wish to have is (2) which refers to the index of these elements separately. Any possible ideas? thanks
c=
{[3,2]} {[4,1]}
{3} {2}
{4} {1}
Adam Danz on 28 Aug 2019
I see. So you want to return the row index of C that, when horizontally concatented, equals the vector in C{1,1}.

MA on 28 Aug 2019
I found the answer if anyone is looking for something similar
for i=2:size(c,1)
if (isequal(c{1,1},cell2mat(c(i,:))))
index=i;
end
end
##### 2 CommentsShowHide 1 older comment
MA on 28 Aug 2019
Thanks alot. It really helps

### More Answers (1)

Luna on 28 Aug 2019
Maybe you can try this piece of code:
cellSizes = cellfun('prodofsize',c);
elementIndices = [];
elementValues = [];
for i = 1:numel(cellSizes)
for j = 1:cellSizes(i)
tempVar = c{i}(j);
elementValues = [elementValues,tempVar];
elementIndices = [elementIndices,find(c{i} == tempVar)];
end
end