MATLAB Answers

## One-to-one correspondence anonymous function

Asked by Arash

### Arash (view profile)

on 10 Feb 2013
Accepted Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

I was wondering if can make an injective (one-to-one correspondence) anonymous function to do this;
if the input was one member from P then function convert it to correspondence member in N, for example if input is x=10 out put will be y=5, x=105-->y=4 and ...
P=[10;100;105;700;943]
N=[5;8;4;11;20]
Thanks in advance, Arash

Walter Roberson

### Walter Roberson (view profile)

on 11 Feb 2013
are your x values always integer? if not there can be a problem.

Sign in to comment.

## 2 Answers

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 10 Feb 2013
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 10 Feb 2013
Accepted Answer

P=[10;100;105;700;700];
N=[5;8;4;11;20];
f=@(x) N(find(P==x));
f(700)

Walter Roberson

### Walter Roberson (view profile)

on 11 Feb 2013
The find() is not needed, P==x can be used directly.
Arash

### Arash (view profile)

on 11 Feb 2013
Thank you Azzi, you helped a lot.

Sign in to comment.

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 10 Feb 2013

@(x) N(ismember(x, P))

Azzi Abdelmalek

on 10 Feb 2013
Maybe it's
ismember(P,x)
Walter Roberson

### Walter Roberson (view profile)

on 11 Feb 2013
Good point.

Sign in to comment.