how to determine that all cell array value exists in other cell array?
51 ビュー (過去 30 日間)
古いコメントを表示
Hello every one
I have a cell array
S=3×1 cell array
[ 29 56 62]
[34 40 62]
[48 52 7]
and other sequence of values in cell array
T{1} for examle:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74
Hiw can I check that all values in S are contain in T?
Thank you
1 件のコメント
the cyclist
2023 年 6 月 14 日
To save anyone else who looks at this from the effort:
S = {[29 56 62];
[34 40 62];
[48 52 7]};
T = {[1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74]};
採用された回答
the cyclist
2023 年 6 月 14 日
This does what I think you want:
S = {[29 56 62];
[34 40 62];
[48 52 7]};
T = {[1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74]};
allSinT = cellfun(@(x,y) all(ismember(x,y),2), S,repmat(T,size(S)))
0 件のコメント
その他の回答 (1 件)
Samya
2023 年 6 月 14 日
編集済み: Samya
2023 年 6 月 14 日
To check if all the values of S are contained in T, you can use the ismember function.
Here's the code to check if all values in S are contained in T{1} specifically:
all(ismember(S{1}, T{1}))
This will return a logical value of true if all the values in S{1} are contained in T{1} and false otherwise.
If you have multiple sequences in T and you need to check if all values in S are contained in any of them, you can use a loop like this:
all_included = false;
for i=1:length(T)
if all(ismember(S{i}, T{i}))
all_included = true;
break;
end
end
This will return a logical value of true in all_included if all the values in S are contained in any of the sequences in T, and false otherwise.
Hope this helps!
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!