Get the index of one cell of a cell array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nicolas Douillet
am 4 Mai 2020
Kommentiert: Ameer Hamza
am 5 Mai 2020
Hi,
From a given cell of a cell array, how is it possible to easily and quickly get its index ?
Thanks for help.
Best.
2 Kommentare
Johannes Hougaard
am 4 Mai 2020
Try reading the help for ind2sub or sub2ind
These functions are valid for cell arrays as well.
Akzeptierte Antwort
Ameer Hamza
am 4 Mai 2020
Suppose you have a cell array
A = {1,2,3,4,5};
and you extract a specific element of this array
a = A(4);
then, for a general case, you can find its index back using
idx = find(cellfun(@(x) isequal(x,a{:}), A))
if all the elements of A are scalar, then you can also write
idx = find([A{:}]==a{1});
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!