Reputation: 269
I need to compare two different arrays in Matlab. It's going to be used for a Yahtzee game. If I have an array that contains [1 2 3 4] and an array that contains [1 2 3 4 5], how do I check if the first array is contained within the second array. I just need to know a T/F result, not anything about which elements are missing, etc.
Upvotes: 1
Views: 1563
Reputation:
another option,
all(intersect(x,y)==x)
but ismember
is probably more efficient....
Upvotes: 0
Reputation: 12345
ismember
will do it. For example:
x = [1 2 3 4]
y = [1 2 3 4 5]
all(ismember(x,y))
You can also use setdiff
. For example:
isempty(setdiff(x,y))
Upvotes: 4