# Get the index of one cell of a cell array

4 visualizzazioni (ultimi 30 giorni)
Nicolas Douillet il 4 Mag 2020
Commentato: Ameer Hamza il 5 Mag 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 CommentiMostra NessunoNascondi Nessuno
Johannes Hougaard il 4 Mag 2020
Try reading the help for ind2sub or sub2ind
These functions are valid for cell arrays as well.
Nicolas Douillet il 4 Mag 2020
Modificato: Nicolas Douillet il 4 Mag 2020
Ok thanks for your reply, but I forgot to mention this is for one dimension cell arrays in my case.

Accedi per commentare.

### Risposta accettata

Ameer Hamza il 4 Mag 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 CommentiMostra NessunoNascondi Nessuno
Nicolas Douillet il 5 Mag 2020
Great, thank you for this very clear answer.
This is the kind of solution I was looking for.
Ameer Hamza il 5 Mag 2020
I am glad to be of help.

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by