if statement not working
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 4 de Dic. de 2012
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?).
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!