フィルターのクリア

vlookup similar operation on unequal matrix size

1 回表示 (過去 30 日間)
David C
David C 2012 年 6 月 12 日
I have a series of timestamps, x1, and values associated with it, y1, and another series of timestamps, x2 (different length) with its own set of associated values, y2.
I want to do a vlookup operation like excel does, and look in x1, match the one to the timestamp in x2, and extract the corresponding values at that index of both y1, and y2
I'm attempting to use logical indexing:
y1=y1(x1==x2)
y2=y2(x1==x2)
but I get an error:
??? Error using ==> eq
Matrix dimensions must agree.
Using one = sign doesn't work either. Is there something that disregards dimension? or am i forced to create an embedded for loop? :(

採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 13 日
[tf, idx] = ismember(x1, x2);
y1 = y1(x1(tf));
y2 = y2(x2(idx(tf)));

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 13 日
one way
[b12,b12] = intersect(x1,x2);
[b21,b21] = intersect(x2,x1);
y1 = y1(b12);
y2 = y2(b21);

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by