find all elements (cells) of a single element (cell) in cell array
Mostrar comentarios más antiguos
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}
3 comentarios
Adam Danz
el 28 de Ag. de 2019
I don't understand, "The answer that I wish to have is (2) which refers to the index of these elements separately"
Adam Danz
el 28 de Ag. de 2019
I see. So you want to return the row index of C that, when horizontally concatented, equals the vector in C{1,1}.
Respuesta aceptada
Más respuestas (1)
Luna
el 28 de Ag. de 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
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!