フィルターのクリア

array comparison. help please!

1 回表示 (過去 30 日間)
Diogo Queirós
Diogo Queirós 2014 年 9 月 16 日
コメント済み: Diogo Queirós 2014 年 9 月 17 日
i have an array:
barr=
'SE BRG'
'PTC 0275'
'PTD 0262'
'PTC 0062'
'PTC 0471'
'PTC 0471 CJ 1'
'PTD 0084'
'PTD 0286'
'PTD 0286 CJ 1'
and a matrix:
pt =
'Name' 'S'
'PTC 0062' [ 500]
'PTC 0275' [ 315]
'PTC 0471' [ 790]
'PTD 0084' [ 500]
'PTD 0262' [ 630]
'PTD 0286' [ 630]
what i want to do is match the 'Name' with the array barr and create a new array with the respective 'S', and the elements that don't exist in the column 'Name' are [0]. so the correct result would be:
barr= Sbarr=
'SE BRG' [ 0]
'PTC 0275' [ 315]
'PTD 0262' [ 630]
'PTC 0062' [ 500]
'PTC 0471' [ 790]
'PTC 0471 CJ 1' [ 0]
'PTD 0084' [ 500]
'PTD 0286' [ 630]
'PTD 0286 CJ 1' [ 0]
can anyone help me with this?

採用された回答

Niko
Niko 2014 年 9 月 16 日
[~,ind]=ismember(barr,pt(2:end,1));
temp=pt(:,2); temp{1}=0;
Sbarr=[barr,temp(ind+1)]
  1 件のコメント
Diogo Queirós
Diogo Queirós 2014 年 9 月 17 日
works perfectly thanks man!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by