Look for string in table and return a number in the same row different column
1 view (last 30 days)
Show older comments
John Marvin Palao
on 21 Sep 2021
Answered: Steven Lord
on 21 Sep 2021
Hi i have a table named TurbulentFittings.xlsx
and i am trying to return values from speKL column by using fitcode entries kind of like VLOOKUP but for string lookup.
here's my code
KLDATA = readtable("TurbulentFittings.xlsx")
fitcode = app.FittingCodeEditField.Value %Fitcode entry
speKL = vlookup("fitcode",KLDATA,2,3,0) %how do i look for the speKL value in the same row as the fitcode? vlookup doesnt work
1 Comment
Sargondjani
on 21 Sep 2021
The function "find" is what you need. Maybe search for "find string in matrix" or in a table
Accepted Answer
Steven Lord
on 21 Sep 2021
I'd probably use matches for text data (and the normal relational operators for numeric data.)
load patients
P = table(LastName, Age, Gender, Height, Weight);
head(P)
Now let's find all patients that are male and are at least 40 years old.
areMale = matches(P.Gender, 'Male'); % Use matches for text
are40OrOlder = P.Age >= 40; % Use relational operators for numbers
P(areMale & are40OrOlder, :)
The row for Mr. Smith, row 1 in P, doesn't show up because he's not old enough. The row for Mr. Johnson, row 2 in P, does show up because he's a male over 40. None of the next 5 lines show up because those patients aren't male. If I'd wanted I could have just gotten the heights of those patients.
% Use curly braces to extract the contained data not a subtable
H = P{areMale & are40OrOlder, 'Height'}
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!