필터 지우기
필터 지우기

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 CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by