Two strcmp conditions in one if statement
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!