if statement not working
Afficher commentaires plus anciens
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
Réponses (1)
Walter Roberson
le 4 Déc 2012
0 votes
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 commentaires
Yasmin Tamimi
le 4 Déc 2012
Modifié(e) : Yasmin Tamimi
le 4 Déc 2012
Walter Roberson
le 4 Déc 2012
In the Excel file, is the date being stored as string or as binary data?
Could you give an example of a date that you know to be present in both files? And could you show the numeric (first output) and text (second output) from xlsread for that date, for both files, entries that you expect to match?
Yasmin Tamimi
le 4 Déc 2012
Yasmin Tamimi
le 4 Déc 2012
Modifié(e) : Walter Roberson
le 4 Déc 2012
Catégories
En savoir plus sur Web Services dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!