Thread Subject: Find the number of different in Matlab

Subject: Find the number of different in Matlab

From: Vinh Le

Date: 19 Mar, 2010 22:14:04

Message: 1 of 4

I wonder if there a Matlab function that returns the number of different element in 2 same length arrays Matlab?

For example
a = [0, 1 , 2, 3, 4]
b = [0, 0, 0 , 0, 4]
compareNumberDifferent(a,b) = 3 as {2 , 3, 4 element in 2 arrays are different}

Subject: Find the number of different in Matlab

From: Oleg Komarov

Date: 19 Mar, 2010 22:28:04

Message: 2 of 4

"Vinh Le" <lekhanhvinh@gmail.com> wrote in message <ho0svc$dfj$1@fred.mathworks.com>...
> I wonder if there a Matlab function that returns the number of different element in 2 same length arrays Matlab?
>
> For example
> a = [0, 1 , 2, 3, 4]
> b = [0, 0, 0 , 0, 4]
> compareNumberDifferent(a,b) = 3 as {2 , 3, 4 element in 2 arrays are different}

numel(setdiff(a,b))

Oleg

Subject: Find the number of different in Matlab

From: Walter Roberson

Date: 19 Mar, 2010 22:47:09

Message: 3 of 4

Vinh Le wrote:
> I wonder if there a Matlab function that returns the number of different
> element in 2 same length arrays Matlab?
>
> For example
> a = [0, 1 , 2, 3, 4]
> b = [0, 0, 0 , 0, 4]
> compareNumberDifferent(a,b) = 3 as {2 , 3, 4 element in 2 arrays are
> different}

sum(a ~= b)

Subject: Find the number of different in Matlab

From: Vinh Le

Date: 19 Mar, 2010 23:28:04

Message: 4 of 4

Thank You Very Much for Your Helps

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com