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!