Is it another command using to compare between vector and cell?

I have this code bellow: when U = [] and has value after , S also the same initila by S = {},
I use IsContainedIn to compare between each value fo U and S, but it doesn't work, an error appear : "Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character vector."
Could you please help me I 'm stuck in this step
for i=1:numel(U)
if ~IsContainedIn(U(i),S{p})
w1 = [w1 U(i)];
end
end
Thanks

6 件のコメント

Daniel M
Daniel M 2019 年 10 月 30 日
Is IsContainedIn a native MATLAB function? I'm having trouble finding it.
Mira le
Mira le 2019 年 10 月 30 日
No it isn't
it a function using in genetic algorithm,
it is better to find a matlab function do the same thing as IsContainedIn
Daniel M
Daniel M 2019 年 10 月 30 日
Right. Well, I'm not sure what you're storing in U and S, but have a look at ismember and strcmp
Alex Mcaulley
Alex Mcaulley 2019 年 10 月 30 日
What is the content of S and U? Are you trying to merge S and U without repetitions?
Mira le
Mira le 2019 年 10 月 30 日
U is a vector
U = [1 2 3]
S = { 1 2 }
Mira le
Mira le 2019 年 10 月 30 日
I ant to check each element of U exist in S, we notice that U is vector and S a cell

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

 採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 10 月 30 日

0 投票

Then, to obtain the elements of U that doesn't exist in S, you can do:
U = [1,2,3];
S = {1,2};
w = U(~ismember(U,cell2mat(S)))

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2019 年 10 月 30 日

コメント済み:

2019 年 10 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by