フィルターのクリア

finding the index of an array in cell array

2 ビュー (過去 30 日間)
Izzat Brgli
Izzat Brgli 2021 年 3 月 28 日
コメント済み: Stephen23 2021 年 3 月 30 日
I'm trying to find out if an array is an element of a cell array and return the index, so I did
arr ={[1,2,3],[4,45,6]}
index = find([arr{:}] == [1,2,3])
but it didn't work. How can I solve it?
thanks in advance

採用された回答

Fangjun Jiang
Fangjun Jiang 2021 年 3 月 29 日
編集済み: Fangjun Jiang 2021 年 3 月 29 日
arr ={[1,2,3],[4,45,6]};
>> index=find(cellfun(@(x) all(x==[1 2 3]),arr))
index =
1
  1 件のコメント
Stephen23
Stephen23 2021 年 3 月 30 日
Simpler and more efficient to use isequal:
arr = {[1,2,3],[4,45,6]};
vec = [1,2,3];
fun = @(a)isequal(vec,a);
idx = cellfun(fun,arr)
idx = 1×2 logical array
1 0

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by