필터 지우기
필터 지우기

manipulate a method contain to compare two lists

조회 수: 4 (최근 30일)
mazari ahmed
mazari ahmed 2015년 3월 8일
답변: mazari ahmed 2015년 3월 14일
l have trouble with the code below. l want to compare two lists of elements to : 1)know wether the neighbours of j are included in k 2)know wether the set of j is equal to k
but matlab returns me an error
if (contains(neighbour_n{k}, neighbour_n{j})||(neighbour_n{j}==neighbour_n{k}));
Undefined function or method 'contains' for input arguments of type 'double'.

채택된 답변

Guillaume
Guillaume 2015년 3월 8일
contains is not a standard matlab function. You can test set membership wih ismember. it'll return a vector of [true, false] values, so if you just want a scalar, yo need to use all.
Similarly, == returns a vector of [true, false] and only works if both matrices / vectors being compared are the same size. To test that two (sorted) sets are identical you'd use |isequal
Thus,
if all(ismember(neighbour_n{j}, set_n{k})) && isequal(set_n{j}, set_n{k})
%do something

추가 답변 (2개)

Jan
Jan 2015년 3월 8일
The error message tells you, that there is no function called "contains". Why do you assume that there is such a function?
Are you sure that you need the elementwise comparison "==" or would isequal be better?

mazari ahmed
mazari ahmed 2015년 3월 14일
it's working look here :
if (((all(ismember(neighbour_n{k}, neighbour_n{j})))||(isequal(neighbour_n{j}, neighbour_n{k})))&&(k~=j));
end

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by