Look for string in table and return a number in the same row different column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
John Marvin Palao
am 21 Sep. 2021
Beantwortet: Steven Lord
am 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 Kommentar
Sargondjani
am 21 Sep. 2021
The function "find" is what you need. Maybe search for "find string in matrix" or in a table
Akzeptierte Antwort
Steven Lord
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!