MATLAB Answers

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

조회 수: 1(최근 30일)
Mira le
Mira le 30 Oct 2019
댓글: Mira le 30 Oct 2019
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

표시 이전 댓글 수: 3
Alex Mcaulley
Alex Mcaulley 30 Oct 2019
What is the content of S and U? Are you trying to merge S and U without repetitions?
Mira le
Mira le 30 Oct 2019
U is a vector
U = [1 2 3]
S = { 1 2 }
Mira le
Mira le 30 Oct 2019
I ant to check each element of U exist in S, we notice that U is vector and S a cell

로그인 to comment.

채택된 답변

Alex Mcaulley
Alex Mcaulley 30 Oct 2019
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)))

  댓글 수: 1

Mira le
Mira le 30 Oct 2019
Thank you so much it works

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by