Find in a cell array?
显示 更早的评论
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 个评论
Jan
2013-8-7
I've deleted the duplicate question.
Elias Berra
2015-11-17
X = my_array_data [row,col] = find(X==21) %In this example, it retrieves the cell location which contains the value 21.
Marwan Malaeb
2022-5-20
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.
采纳的回答
更多回答(2 个)
Bill Tubbs
2022-2-15
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 个评论
hongyi xu
2022-4-17
Genius! Your supplement exactly fits my question.
Caroline
2013-8-7
编辑:Azzi Abdelmalek
2013-8-7
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 个评论
Azzi Abdelmalek
2013-8-7
Why initializing cellarray_new to 0?
Jan
2013-8-7
I assume that "cell array" implies, that the array is a cell.
Filza Ashraf
2014-5-22
how can i find a pixel intensity if cell contains an image or image is stored in cell???
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!