How to create a corresponce between 2 column vector? (Replicating the vlookup funcion of excel)

1 次查看(过去 30 天)
Hi!
I have the next two vectors (all are numbers and type double)=
A=[1;2;3;4;5]
B=[30;40;50;60;70]
Lets say that the elements on B are a "correspondence" with the elements on A.
And I have another vector, C, which contains some of the elements that belongs to A.
C=[2,3,4]
I want to know how I can create a fourth vector, D, which associates those elements in B that are in the same possition than those in C. So I want to obtain:
D=[40;50;60]
How can I do this? In a matter of saying this I want to "replicate" the Vlookup function from excel.
Can anyone help me?
Thanks a lot!

采纳的回答

Roger Stafford
Roger Stafford 2016-4-30
[L,ix] = ismember(C,A);
D = B(ix(L));

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by