find the relatonship between two variables

Hello all,
I would like to create the command in order to create the variable following relationship between two variables such as: if i = [ 1 4 7 10 ] then j = [1 2 3 4]. ex if i =1 then j =1 , if i = 7 then j = 3 and so on.
Thanks you for your helping.

 採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 17 日

0 投票

ivals = [1 4 7 10 ];
jvals = [1 2 3 4];
j = jvals(find(i == ivals));
In the particular case where the ivals are strictly increasing then you could also use
j = interp1(ivals, jvals, i);

1 件のコメント

Nam
Nam 2015 年 6 月 17 日
Great !!! Thanks you so much :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

Nam
2015 年 6 月 17 日

コメント済み:

Nam
2015 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by