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

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by