フィルターのクリア

Retrieving Rows based on Columns

1 回表示 (過去 30 日間)
RDG
RDG 2013 年 7 月 3 日
Suppose,
% double
var1=[ 1 1 2 4 5
2 14 15 16 17];
% cell
var2={ 1 5 6 7
3 7 6 5
4 2 5 9
2 1 5 7};
How can I retrieve the rows in var2 (column 1) which corresponds to var1 (column 1).
Desired Result:
1 5 6 7
2 1 5 7
P/S: If it's not too troublesome, can you please include an explanation as well? I would like to learn from it.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 3 日
c1=cell2mat(var2(:,1))
idx=cell2mat(arrayfun(@(x) find(ismember(c1,x)),var1(:,1),'un',0))
out=var2(idx,:)
  1 件のコメント
RDG
RDG 2013 年 7 月 3 日
Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by