diff --git a/ScapulaMeasurements.xls b/ScapulaMeasurements.xls deleted file mode 100644 index 23f2469..0000000 Binary files a/ScapulaMeasurements.xls and /dev/null differ diff --git a/anatomy.xls b/anatomy.xls new file mode 100644 index 0000000..0ea3abb Binary files /dev/null and b/anatomy.xls differ diff --git a/scapula_measure.m b/scapula_measure.m index e383a6c..e2bc013 100644 --- a/scapula_measure.m +++ b/scapula_measure.m @@ -1,83 +1,82 @@ function scapula_measure(caseID) %%SCAPULA_MEASURE fills the Shoulder database with scapula anatomical data % % This function fills the Shoulder database with the scapula anatomical % data of the case given as input. The anatomical measurements are stored % simultaneously in a XLS file and in the MySQL database. % % USE: scapula_measure(caseID) % % INPUT caseID: Case IDs for which you want to compute scapula anatomical % data. Cell array that stores the case IDs as a char in the form 'P###' or % 'N###' (starts with "P" or "N" followed by 1 to 3 digits). % % REMARKS The anatomical data are saved in the ScapulaAnatomicalData.xls % file. % % created with MATLAB ver.: 8.6.0.267246 (R2015b) on Windows 7 % Author: EPFL-LBO-VMC % Date: 20-Apr-2017 % % Check validity of input argument (cell array) validateattributes(caseID,{'cell'},{'nonempty'}); +[~,~,currDatabase] = xlsread('anatomy.xls'); +currDatabaseCaseIDlist = currDatabase(2:end,1); + for i = 1:length(caseID) % Check validity of input arguments (char and format 'P###' or 'N###') validateattributes(caseID{i},{'char'},{'nonempty'}); if (numel(regexp(caseID{i},'^[PN]\d{1,3}$')) == 0) error(['Invalid format of CaseID: ' caseID{i} '. CaseID must start with "P" or "N" and be followed by 1 to 3 digits.']); end % Get CT directory adress from CT database location and case ID CTDatabaseLocation = 'Z://data'; % Location of the CT database levelDir1 = caseID{i}(1); if (length(caseID{i}(2:end)) < 2) levelDir2 = '0'; levelDir3 = '0'; elseif (length(caseID{i}(2:end)) < 3) levelDir2 = '0'; levelDir3 = caseID{i}(2); else levelDir2 = caseID{i}(2); levelDir3 = caseID{i}(3); end FindCaseCTFolder = dir([CTDatabaseLocation '/' levelDir1 '/' levelDir2 '/' levelDir3 '/' caseID{i} '*']); if (isempty(FindCaseCTFolder)) error(['Missing CT directory for CaseID: ' caseID{i}]); end CaseID_IPP = FindCaseCTFolder.name; CaseCTFolder = [CTDatabaseLocation '/' levelDir1 '/' levelDir2 '/' levelDir3 '/' CaseID_IPP]; % Compute scapula measurements and store in the XLS database if exist([CaseCTFolder '/CT-' CaseID_IPP '-1/amira'],'dir') == 7 %if a folder "amira" exist, the patient name is added to the "measured" column finalDirectory = [CTDatabaseLocation '/' levelDir1 '/' levelDir2 '/' levelDir3] ; - result = scapula_calculation(CaseID_IPP, finalDirectory, levelDir1); % Function that calculates the anatomical datas - vars = fieldnames(result); - - if(~exist('Output','var')) - Output = cell(length(caseID)+1,length(vars)); + anatomy = scapula_calculation(CaseID_IPP, finalDirectory, levelDir1); % Function that calculates the anatomical data + + % Write to XLS file + % Replace line if already existing or append + if(any(strcmp(currDatabaseCaseIDlist, caseID{i}))) + xlswrite('anatomy.xls',struct2cell(anatomy)','Feuil1',['A' int2str(find(strcmp(currDatabaseCaseIDlist, caseID{i}))+1)]); + else + xlswrite('anatomy.xls',struct2cell(anatomy)','Feuil1',['A' int2str(length(currDatabaseCaseIDlist)+1+i)]); end - for m=1:length(vars) - Output{1,m}= vars{m}; % Write the fieldname in the first line of output array - Output{i+1,m} = result.(vars{m}); - end - else error(['Amira files missing for CaseID: ' caseID{i}']); end end - delete('ScapulaMeasurements.xls'); - xlswrite('ScapulaMeasurements.xls',Output); %Write to the excel file end \ No newline at end of file