Find in a cell array?
Afficher commentaires plus anciens
Hello all,
Suppose a cell array 10x1 consisted of random numbers from 1 to 5. How can I find the locations for number 5?
All the best,
MhD
3 commentaires
Jan
le 7 Août 2013
I've deleted the duplicate question.
Elias Berra
le 17 Nov 2015
X = my_array_data [row,col] = find(X==21) %In this example, it retrieves the cell location which contains the value 21.
Marwan Malaeb
le 20 Mai 2022
call this array for example X
type k=find(X==5)
it will return for you the number of the cell that has the value of 5.
Réponse acceptée
Plus de réponses (2)
Bill Tubbs
le 15 Fév 2022
Just in case someone comes here looking to do this with a cell array of chars as I was, it's quite easy this way:
my_cell_array = {'a', 'b', 'c'};
i = find(strcmp(my_cell_array, 'b'));
assert(i == 2)
1 commentaire
hongyi xu
le 17 Avr 2022
Genius! Your supplement exactly fits my question.
Caroline
le 7 Août 2013
Modifié(e) : Azzi Abdelmalek
le 7 Août 2013
cellarray_new = zeros; %initializing the array
ind = 1; %indices for new array
for j = 1:10
if (cellarray(j) == 5)
cellarray_new(ind) = j;
ind = ind + 1;
end
end
the array cellarray_new will contain all the indices of the original cell array that contain the number 5
3 commentaires
Azzi Abdelmalek
le 7 Août 2013
Why initializing cellarray_new to 0?
Jan
le 7 Août 2013
I assume that "cell array" implies, that the array is a cell.
Filza Ashraf
le 22 Mai 2014
how can i find a pixel intensity if cell contains an image or image is stored in cell???
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!