Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character vector.

22 ビュー (過去 30 日間)
Ioannis Vourvachakis 2021 年 11 月 5 日
コメント済み: Stephen 2021 年 11 月 6 日
I have a cell array A
2×1 cell array
{}
{}
and I have a cell array B, that is a 1×6 cell array.
In B,
B{:,6} contains the below elements
2×1 cell array
{}
{}.
I want to use ismember, to extract the value 321, that it is contaιnes in both arrays.
If I try ismember(A,B{:,6}),
it sais error because Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character vector.
What can I do?
Thank you very much.
2 件のコメント表示非表示 1 件の古いコメント
Stephen 2021 年 11 月 6 日

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

採用された回答

Stephen 2021 年 11 月 5 日

Why are you inefficiently storing scalar numerics in cell arrays?
Using numeric arrays would be much simpler and avoid this error.
"I want to use ismember, to extract the value 321, that it is contaιnes in both arrays."
If the goal is really to get the common members, why not just use INTERSECT? (which once again, is much easier with numeric arrays).
Given that inefficent data:
A = {321,640}
A = 1×2 cell array
{} {}
B = [cell(2,5),{321;278}]
B = 2×6 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {}
C = intersect([A{:}],[B{:,6}])
C = 321
or
X = ismember([A{:}],[B{:,6}])
X = 1×2 logical array
1 0
D = A(X)
D = 1×1 cell array
{}

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

その他の回答 (1 件)

Matt J 2021 年 11 月 5 日

It is puzzling that A and B are cell arrays when they could easily just be vectors. Nevertheless, they can be converted with cell2mat:
ismember(cell2mat(A),cell2mat(B{6}))

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

Community Treasure Hunt

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

Start Hunting!