if statement not working
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey all,
I am comparing data I have with a larger one in excel, but the results I am getting are not what I am looking for although I feel that my code is logic:
for i = 1:length(Normal)
for j = 1:length(Patient_ID)
if strcmp(Normal(i), Patient_ID (j)) == 1 && strcmp(Normal_dates(i), Date_Attended_Clinic (j)) == 1
[num2, txt2]= xlsread('ExcelMainExport_ALL.xls',1, sprintf('A%d:IP%d',j,j));
xlswrite('Data_Collected_Normal.xls', txt1, i, 'A1:IP1')
xlswrite('Data_Collected_Normal.xls', txt2, i,'A2:IP2')
warning off MATLAB:xlswrite:AddSheet
end
end
end
Now, what I'm getting in Data_Collected normal are the correct string names, so the first part of the if statement is achieved but the second one regarding the dates is not!! In my excel file I have redundant data but each one has a different date. Normal and Normal_Dates are 70X1 cell arrays, while Patient_ID and Date_Attended_Clinic are 2626X1 cell arrays
댓글 수: 0
답변 (1개)
Walter Roberson
2012년 12월 4일
Just as a wild hypothesis: is it possible that you need strcmpi() on the dates? If they do not happen to match upper/lower-case ?
In both cases are the dates exactly the same format? For example, it isn't the case that one of them starts 3/ and the other starts 03/ for the same date? And the order of the parts of the dates are exactly the same?
I am also wondering if you might at some point be converting from Excel binary date format to printable date format. If you are then you may need to take into account that Excel date numbers start at a different base than MATLAB dates do, and Excel date numbers have a leap-year bug for the year 1900, leading to a potential 1 day difference for dates from March 1 1900 onward. When an Excel binary date that is known to Excel as being a date, is converted by xlsread() then the resulting text field should be correct (except perhaps Jan/ Feb 1900?).
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!