How to replace numbers in one vector according to two 'translation vectors'

5 ビュー (過去 30 日間)
Clemens Gersch
Clemens Gersch 2020 年 9 月 16 日
コメント済み: jonas 2020 年 9 月 16 日
Hi,
I probably just googled for the wrong terms as this seems to be a very common problem.
I have a vector A that needs to be translated into the vector D according to the rules set in vectors B and C.
A = [3; 5; 8];
B = [3; 4; 5; 7; 8];
C = [1; 2; 3; 4; 5];
D = ?
B and C say, how the translation works. Example 1: a 3 in A must become a 1 in D. Example 2: a 7 in A (although there isn't any, but if there were) must become a 4 in D.
So the solution for D must be [1; 3; 5]. How can I get there?

採用された回答

jonas
jonas 2020 年 9 月 16 日
編集済み: jonas 2020 年 9 月 16 日
D = interp1(B,C,A)
  2 件のコメント
Clemens Gersch
Clemens Gersch 2020 年 9 月 16 日
編集済み: Clemens Gersch 2020 年 9 月 16 日
Quite a "think outside of the box" idea. I know interp1, but would have never got to the point of using it in this constellation.
Works fine, thanks.
jonas
jonas 2020 年 9 月 16 日
My pleasure!
It makes sense if you think of your translation vectors as a function.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by