Two strcmp conditions in one if statement

2 ビュー (過去 30 日間)
Emilee Cowan-Nelson
Emilee Cowan-Nelson 2022 年 3 月 21 日
コメント済み: Star Strider 2022 年 3 月 21 日
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.

採用された回答

Star Strider
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 件のコメント
Emilee Cowan-Nelson
Emilee Cowan-Nelson 2022 年 3 月 21 日
Thank you!! I found the error. The dates lined up, but they weren't in the same format so it couldn't compare them which is why it was coming out blank. Thank you for your help(:
Star Strider
Star Strider 2022 年 3 月 21 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by