0001 function mergedData=mergeTextDataAndData(textdata,data,headings)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if ~exist('headings','var');
0021 headings=1;
0022 fprintf('%s\n','Assuming there were headings in the original xls file');
0023 end
0024 if headings==1
0025 start=2;
0026 else
0027 start=1;
0028 end
0029
0030
0031 fprintf('%s\n','Checking for exceptions in otherwise numeric columns, e.g. NaN');
0032 fprintf('%s\n','Checking for exceptions in otherwise numeric columns, e.g. -');
0033 fprintf('%s\n','Checking for exceptions in otherwise numeric columns, e.g. Not calculated');
0034 fprintf('%s\n','Checking for exceptions in otherwise numeric columns, e.g. #N/A');
0035 fprintf('%s\n','Checking for empty cells in otherwise numeric columns, e.g. []');
0036 [ylt,xlt]=size(textdata);
0037 for y=1:ylt
0038 for x=1:xlt
0039 if strcmp(textdata{y,x},'NaN')
0040 textdata{y,x}='';
0041 end
0042 end
0043 end
0044 for y=1:ylt
0045 for x=1:xlt
0046 if strcmp(textdata{y,x},'-')
0047 textdata{y,x}='';
0048 end
0049 end
0050 end
0051 for y=1:ylt
0052 for x=1:xlt
0053 if strcmp(textdata{y,x},'Not calculated')
0054 textdata{y,x}='';
0055 end
0056 end
0057 end
0058 for y=1:ylt
0059 for x=1:xlt
0060 if strcmp(textdata{y,x},'#N/A')
0061 textdata{y,x}='';
0062 end
0063 end
0064 end
0065
0066 for y=1:ylt
0067 for x=1:xlt
0068 if isempty(textdata{y,x})
0069 textdata{y,x}='';
0070 end
0071 end
0072 end
0073
0074 mergedData=textdata;
0075 dataCol=1;
0076 beginData=0;
0077 for x=1:xlt
0078
0079 if min(strcmp(textdata(start:ylt,x),''))==1
0080 beginData=1;
0081 fprintf('%s\n',['Merging numerical data into column ' int2str(x)]);
0082 for y=start:ylt
0083 if (y-start+1)>size(data,1)
0084
0085
0086 mergedData{y,x}=NaN;
0087 else
0088 mergedData{y,x}=data(y-start+1,dataCol);
0089 end
0090 end
0091 dataCol=dataCol+1;
0092 if dataCol>size(data,2)
0093 break
0094 end
0095 else
0096
0097 if beginData==1
0098 dataCol=dataCol+1;
0099 end
0100 end
0101 end
0102
0103 if dataCol<size(data,2)+1
0104 p=1;
0105 while dataCol<size(data,2)+1
0106 for y=start:ylt
0107 mergedData{y,x+p}=data(y-start+1,dataCol);
0108 end
0109 p=p+1;
0110 dataCol=dataCol+1;
0111 end
0112 end
0113
0114
0115
0116