フィルターのクリア

Create new table variable filled with values from another table

1 回表示 (過去 30 日間)
Haris K.
Haris K. 2020 年 10 月 17 日
コメント済み: Ameer Hamza 2020 年 10 月 17 日
Hi. I have the following tabels, T1 and T2:
Name1=["A","B","C","D"]'
Des1=["Shoubidou","Abra","Ca","Dabra"]'
T1=table(Name1, Des1)
Name2 =["C","B","B","A","B","B","A"]'
T2 = table(Name2)
I would like to create a new variable Des2 (in table T2), which for each T2 element contains the description taken from T1. The final result should be:
Des2=["Ca","Abra","Abra","Shoubidou","Abra","Abra","Shoubidou"]'
T2final = table(Name2, Des2)
One way to do this is to iterate over the elements of T2. Is there any other way without a for-loop?
Notice that some elements in T1 it is possible that they are not contained in T2 (just in case this changes your solution).

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 17 日
Try this
Name1=["A","B","C","D"]'
Des1=["Shoubidou","Abra","Ca","Dabra"]'
T1=table(Name1, Des1)
Name2 =["C","B","B","A","B","B","A"]'
T2 = table(Name2)
[~, idx] = ismember(Name2, Name1);
T2.Des2 = Des1(idx);
  2 件のコメント
Haris K.
Haris K. 2020 年 10 月 17 日
You're da man. Thx!
Ameer Hamza
Ameer Hamza 2020 年 10 月 17 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by