One-to-one correspondence anonymous function

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 10 日
編集済み: Azzi Abdelmalek 2013 年 2 月 10 日

1 投票

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

2 件のコメント

Walter Roberson
Walter Roberson 2013 年 2 月 11 日
The find() is not needed, P==x can be used directly.
Arash
Arash 2013 年 2 月 11 日
編集済み: Arash 2013 年 2 月 11 日
Thank you Azzi, you helped a lot.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 2 月 10 日

0 投票

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

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 10 日
Maybe it's
ismember(P,x)
Walter Roberson
Walter Roberson 2013 年 2 月 11 日
Good point.

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by