Look for string in table and return a number in the same row different column
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Sargondjani
2021년 9월 21일
The function "find" is what you need. Maybe search for "find string in matrix" or in a table
채택된 답변
Steven Lord
2021년 9월 21일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!