Fetching variable from another variable

32 ビュー (過去 30 日間)
kash
kash 2012 年 7 月 19 日
I have two sets of variables
A=
'yar12' 'hi' 'hello' 'hi' 'hello'
'yar13' hello' 'hello' 'hi' 'hello'
'yar14' 'hi' 'hi' 'hi' 'hello'
'yar15' 'hello' 'hi' 'hi' 'hi'
'yar16' 'hello' 'hi' 'hi' 'hello'
'yar17' 'hi' 'hi' 'hi' 'hi'
and
B=
'yar13' hi' 'hello' 'hello' 'hello'
'yar16' 'hi' 'hello' 'hi' 'hello'
'yar17' 'hello' 'hi' 'hello' 'hi'
The size of both matrix are different by comparing first column,i want to fetch values(2nd to 5th column) from A correspnding to 1st column of B,So i need output as
C=
'yar13' hello' 'hello' 'hi' 'hello'
'yar16' 'hello' 'hi' 'hi' 'hello'
'yar17' 'hi' 'hi' 'hi' 'hi'
PLease provide assistance

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 19 日
[tf, idx] = ismember(B(:,1), A(:,1));
C = A(idx,:);
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 7 月 19 日
C = A(ismember(A(:,1),B(:,1)),:);
kash
kash 2012 年 7 月 19 日
Thanks a lot Andreei

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by