Mapping non-integer values of matrix to another matrix via mapping table

2 ビュー (過去 30 日間)
Distelfink
Distelfink 2022 年 3 月 7 日
コメント済み: Distelfink 2022 年 3 月 7 日
Dear all,
I would like to do a mapping operation as in this thread, only with real numbers and not integers. To illustrate, suppose I have the vector
v=[0.5 1.3 0.7 3 0.7 1.3];
as well as a mapping table
m=[0.5 4; 0.7 5; 1.3 6; 3 7]
m = 4×2
0.5000 4.0000 0.7000 5.0000 1.3000 6.0000 3.0000 7.0000
I would like to transform v via mapping m into
w=[4 6 5 7 5 6];
if possible without using a loop. Does anyone have an idea? Thanks a lot in advance for your time!

採用された回答

KSSV
KSSV 2022 年 3 月 7 日
編集済み: KSSV 2022 年 3 月 7 日
v=[0.5 1.3 0.7 3 0.7 1.3];
m=[0.5 4; 0.7 5; 1.3 6; 3 7] ;
w=[4 6 5 7 5 6];
[c,ia] = ismember(v,m(:,1)) ;
iwant = m(ia,2)
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 3 月 7 日
I would suggest ismembertol for this purpose
Distelfink
Distelfink 2022 年 3 月 7 日
Thanks to both of you for the helpful answers!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by