Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to find a unique value in a matrix using matlab
Replies: 5   Last Post: Oct 8, 2013 3:03 AM

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,822 Registered: 7/26/08
Re: How to find a unique value in a matrix using matlab
Posted: Oct 8, 2013 3:03 AM

gan kelly <gansiewlee87@gmail.com> wrote in message <7485fcf4-74d4-426a-a880-836c6ec6fca6@googlegroups.com>...
> Hi, everyone.
> Let's say I have following (3x3)matrix A:
>
> 0 1 3
> 0 0 3
> 0 0 0
>
> My question is how to find out the unique value in that matrix by using matlab? In this case, the result should be 1. I have tried used the
>
> value=unique(A)
>
> but it returned a vector {0;1;3} is not what I want.
>
> I much appreciate if you guys can help me solve this problem. Thank you!

>> A=[0 1 3;
0 0 3;
0 0 0]

A =

0 1 3
0 0 3
0 0 0

>> b=unique(A)

b =

0
1
3

>> b(histc(A(:),b)==1)

ans =

1

% Bruno

Date Subject Author
10/7/13 gan kelly
10/7/13 Peter Simon
10/7/13 gan kelly
10/7/13 dpb
10/7/13 Curious
10/8/13 Bruno Luong