This solution creates a set of logical vectors that identify rows of dpt table that are satisfied by the user input. It then combines those logical vectors to identify the row(s) that is satisfied by all inputs. Next I added a sanity check that makes sure that one and only one row was selected. Then it returns the 'value' of that row.
isGenderMatch = strcmpi(bpt.gender, sex);
isLessThanSys = sysbp < bpt.systolichigh;
isGreaterThansSys = sysbp >= bpt.systoliclow;
isLessThanDia = diabp < bpt.diastolichigh;
isGreaterThansDia = diabp >= bpt.diastoliclow;
rowIdx = isGenderMatch & isLessThanSys & isGreaterThansSys & isLessThanDia & isGreaterThansDia;
if sum(rowIdx) == 0
error('No matches found.')
end
if sum(rowIdx) > 1
error('More than 1 match found! Rows [%s].', num2str(find(rowIdx)))
end
test = bpt.values(rowIdx);
Best Answer