File Exchange

image thumbnail

vlookup - similar to MS Excel function

version 1.0 (1.57 KB) by

A matrix version of VLOOKUP similar to MS Excel function.



View License

VLOOKUP the function as vlookup in Excel

[content, index] = vlookup(m, e, column, lookcolumn) look for 'e' in the 'lookcolumn'-th column of 'm', and return the coresponding 'column'-th element of 'm' in the same row.

the 'm' could be a numeric matrix of a cell matrix.

lookcolumn is 1 by default if omitted.


m = {1, 'a', [2 3];
2, 'b', 'cd'
3, 'a', true;};
[content, index] = vlookup(m, 'a', 3, 2) then
content = {[2 3], 1};
index = [1;3]


Comments and Ratings (5)

Y He

Y He (view profile)

Victor Lejona


Sergiy (view profile)

Darin McCoy

BTW - you might want to consider making a change on line 33 of this from

index = find(strcmp(e, m(:, lookcolumn)));


index = find(strcmpi(e, m(:, lookcolumn)));

The second one finds things if they are not case sensitive

Darin McCoy

This is really helpful!

MATLAB Release
MATLAB 7.11 (R2010b)
Tags Add Tags

Inspired: VLOOKUP

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today