mergeTextDataAndData

PURPOSE ^

merge textdata and data imported from .xls file assuming that the first

SYNOPSIS ^

function mergedData=mergeTextDataAndData(textdata,data,headings)

DESCRIPTION ^

merge textdata and data imported from .xls file assuming that the first
row of textdata is column headings

 mergedData=mergeTextDataAndData(textdata,data)

INPUT
 textdata      cell array from .xls import
 data          matrix with numeric data from .xls import

OPTIONAL INPUT
 headings      {(1),0}, zero if no column headings

OUTPUT
 mergedData    merged cell array with all data from .xls import

 Ronan Fleming 29/10/2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mergedData=mergeTextDataAndData(textdata,data,headings)
0002 %merge textdata and data imported from .xls file assuming that the first
0003 %row of textdata is column headings
0004 %
0005 % mergedData=mergeTextDataAndData(textdata,data)
0006 %
0007 %INPUT
0008 % textdata      cell array from .xls import
0009 % data          matrix with numeric data from .xls import
0010 %
0011 %OPTIONAL INPUT
0012 % headings      {(1),0}, zero if no column headings
0013 %
0014 %OUTPUT
0015 % mergedData    merged cell array with all data from .xls import
0016 %
0017 % Ronan Fleming 29/10/2008
0018 
0019 %check for headings
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 %checking for exceptions in otherwise data columns
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 %replace empty cells with blank string
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 %preallocate
0074 mergedData=textdata;
0075 dataCol=1; 
0076 beginData=0;
0077 for x=1:xlt 
0078     %check for blank column
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                 %if the last rows are NaN then this is needed as data will
0085                 %be too short
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         %data can have empty columns corresponding to textdata columns
0097         if beginData==1
0098             dataCol=dataCol+1;
0099         end
0100     end 
0101 end
0102 %data column might be the last column of original xls file
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 % for x=1:137 gMW{x,1}=iCore.genes{x}; for y=1:5300 if
0116 % strncmp(iCore.genes{x},mergedData{y,1},length(iCore.genes{x})) gMW{x,2}=d(y); end; end; end;

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003