フィルターのクリア

vlookup type matrix creating

2 ビュー (過去 30 日間)
Rafael Schwarzenegger
Rafael Schwarzenegger 2020 年 2 月 13 日
コメント済み: Stephen23 2020 年 2 月 14 日
Hello, I would like to create a vlookup (excel) type operation that searches matrix A in matrix B and creates matrix C. How could I do it please in the most easy way?
A = [0 0 1 0.25;
0 1 1 0.75]
B = [0 0 1;
0 1 1;
0 1 1;
0 0 1;]
C = [0 0 1 0.25;
0 1 1 0.75;
0 1 1 0.75;
0 0 1 0.25;]
Thank you for any ideas!

採用された回答

Steven Lord
Steven Lord 2020 年 2 月 13 日
Since this sounds like it might be a homework question, I'm only going to point you in the direction of a useful function: ismember (with the 'rows' option.)

その他の回答 (1 件)

Rafael Schwarzenegger
Rafael Schwarzenegger 2020 年 2 月 14 日
This might do:
BB = zeros(4,4);
for i=1:2
temp = [A(i,1:end-1)==B]; temp = logical(prod(temp,2));
BB(temp,:) = repmat(A(i,:),sum(temp),1);
end
  1 件のコメント
Stephen23
Stephen23 2020 年 2 月 14 日
The MATLAB way:
>> [~,X] = ismember(B,A(:,1:3),'rows');
>> C = A(X,:)
C =
0.00000 0.00000 1.00000 0.25000
0.00000 1.00000 1.00000 0.75000
0.00000 1.00000 1.00000 0.75000
0.00000 0.00000 1.00000 0.25000

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

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by