Two strcmp conditions in one if statement
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to write a code to organize my data into specific timepoints. I need to compare data from two cell arrays. If participant IDs AND dates from both arrays match, I want to put the data into the appropriate timepoint. I have written the code below, however the output is blank.
load('affected') %Data for only the affected arm of each participant in cell array
load('tally_full') %Tally sheet data in cell array
timepoint1 = [];
timepoint2 = [];
timepoint3 = [];
timepoint4 = [];
for length_affected = 2:length(affected) %First row is column headings so I'm starting at row 2
for length_tally = 3:length(tally_full) %First two rows are column headings so I'm starting at row 3
if strcmpi(affected(length_affected,1), tally_full(length_tally,1)) && strcmp(affected(length_affected,15), tally_full(length_tally,134))
timepoint1 = [timepoint1; affected(length_affected,:), tally_full(length_tally,134)];
elseif strcmpi(affected(length_affected,1), tally_full(length_tally,1)) && strcmp(affected(length_affected,15), tally_full(length_tally,135))
timepoint2 = [timepoint2; affected(length_affected,:), tally_full(length_tally,135)];
elseif strcmpi(affected(length_affected,1), tally_full(length_tally,1)) && strcmp(affected(length_affected,15), tally_full(length_tally,136))
timepoint3 = [timepoint3; affected(length_affected,:), tally_full(length_tally,136)];
elseif strcmpi(affected(length_affected,1), tally_full(length_tally,1)) && strcmp(affected(length_affected,15), tally_full(length_tally,137))
timepoint4 = [timepoint4; affected(length_affected,:), tally_full(length_tally,137)];
end
end
end
%Column 1 for both affected and tally_full are participant IDs
%Column 15 in affected is the date in numerical form, column 134 in tally_full is date in numerical form for timepoint 1, column 135 is
%timepoint 2, etc.
I have double checked manually and the IDs and dates are in the same format in both sheets, and the IDs and dates of each participant line up. I don't get any errors when I run the code, I simply get blank doubles for each of the timepoints.
댓글 수: 0
채택된 답변
Star Strider
2022년 3월 21일
‘I don't get any errors when I run the code, I simply get blank doubles for each of the timepoints.’
That would indicate to me that the if conditions are not being met.
You need to take the strcmpi arguments apart to discover the reason. Choose appropriate values for ‘length_affected’ and ‘length_tally’ and check the results for each argument.
Then check the strcmpi results to see if the logical outputs match what you would expect from the arguments to them.
.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!