Hi,
I am trying to count the possible recipient matches in an excel file(attached). I have a donor and multiple recipients along with the state (healthy or unhealthy) in different columns. I want to count the state healthy when it corresponds with the elements in recipient’s column and the donor column as shown in the brown colored cells. If an element/s in the recipient column matches an element/s in set {12,13,14}, number of matches should be counted (only for donor =1)
For instance:
we have B2, C2, D2 fulfill the condition with 2 matches. 1 with 13, and 1 with 14
Another example, we have B5, C5, D5 fulfill the condition with 3 matches. 1 with 12, 1 with 13, and 1 with 14
I need to count all those matches. Any suggestions?
Thanks!!

 채택된 답변

Guillaume
Guillaume 2018년 2월 19일

1 개 추천

desiredrecipients = [12 13 14];
desireddonor = 1;
desiredstate = 'Healthy';
t = readtable('TestHealthy.xls'); %read excel file
t.Recipients = rowfun(@(rec) str2double(strsplit(rec, ',')), t, 'InputVariables', 'Recipients', 'ExtractCellContents', true, 'OutputFormat', 'cell'); %split strings and convert to double
t.MatchedRecipients = rowfun(@(rec) sum(ismember(rec, desiredrecipients)), t, 'InputVariables', 'Recipients', 'ExtractCellContents', true, 'OutputFormat', 'uniform') %count the number of matched recipients in each row
totalcount = sum(t.MatchedRecipients(t.Donor == desireddonor & strcmp(t.State, desiredstate)))

추가 답변 (1개)

aqua blue
aqua blue 2018년 2월 20일

0 개 추천

Thank you Guillaume!!

댓글 수: 1

Star Strider
Star Strider 2018년 2월 20일
The most appropriate way to thank Guillaume is to Accept his answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기

질문:

2018년 2월 19일

댓글:

2018년 2월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by