From: Fraser Dickson on
Hi im trying to use the ismember() func to find out how many values in one matrix are present in the other matrix and that works find

x = sum(ismember(matrixa,matrixb));

but what i also want to know is how do i extract the value in the matrix that is equal

i.e

a = [1;3;5;7;9]
b = [1;5;8;10]

how can i get x = 5 ( as it is present in both matrixes)

Thanks
From: Jos (10584) on
"Fraser Dickson" <fraser.dickson(a)gmail.com> wrote in message <hna8tu$1ru$1(a)fred.mathworks.com>...
> Hi im trying to use the ismember() func to find out how many values in one matrix are present in the other matrix and that works find
>
> x = sum(ismember(matrixa,matrixb));
>
> but what i also want to know is how do i extract the value in the matrix that is equal
>
> i.e
>
> a = [1;3;5;7;9]
> b = [1;5;8;10]
>
> how can i get x = 5 ( as it is present in both matrixes)
>
> Thanks

help intersect

Jos
From: Bruno Luong on
"Fraser Dickson" <fraser.dickson(a)gmail.com> wrote in message <hna8tu$1ru$1(a)fred.mathworks.com>...
> Hi im trying to use the ismember() func to find out how many values in one matrix are present in the other matrix and that works find
>
> x = sum(ismember(matrixa,matrixb));
>
> but what i also want to know is how do i extract the value in the matrix that is equal
>
> i.e
>
> a = [1;3;5;7;9]
> b = [1;5;8;10]
>
> how can i get x = 5 ( as it is present in both matrixes)
>

INTERSECT can output the indexes for both arrays.

Bruno
From: Jan Simon on
Dear Fraser!

> Hi im trying to use the ismember() func to find out how many values in one matrix are present in the other matrix and that works find
>
> x = sum(ismember(matrixa,matrixb));
>
> but what i also want to know is how do i extract the value in the matrix that is equal

If you've called ISMEMBER, you can use its answer!
isCommon = ismember(matrixa,matrixb);
numberOfCommon = sum(isCommon)
valueCommon = matrixa(isCommon)

Good luck, Jan