1

我需要编写一个代码,它为 cellarray GO 的第四列的每个单元格中的字符出现次数添加额外的列:

GO:
      'GO:0008150'    [1]    [1]    'a'
      'GO:0016740'    [2]    [2]    'b'
      'GO:0006412'    [2]    [2]    'b'
      'GO:0016787'    [2]    [3]    'c'
      'GO:0006810'    [2]    [4]    'd'
      'GO:0016787'    [3]    [3]    'c'
      'GO:0004672'    [3]    [3]    'c'
      'GO:0016779'    [3]    [3]    'c'
      'GO:0005215'    [3]    [3]    'c'
      'GO:0006810'    [3]    [4]    'd'
      'GO:0004386'    [3]    [4]    'd'
      'GO:0003774'    [3]    [4]    'd'
      'GO:0016298'    [3]    [4]    'd'
      'GO:0016192'    [3]    [5]    'e'
      'GO:0006412'    [3]    [2]    'b'
      'GO:0005215'    [3]    [3]    'c'
      'GO:0006810'    [4]    [4]    'd'
      'GO:0004386'    [4]    [4]    'd'
      'GO:0003774'    [4]    [4]    'd'
      'GO:0016298'    [4]    [4]    'd'
      'GO:0030533'    [4]    [4]    'd'
      'GO:0030533'    [4]    [4]    'd'
      'GO:0016192'    [4]    [5]    'e'

结果 GO cellarray 应如下所示(从 0 值开始):

GO:     
  'GO:0008150'    [1]    [1]    'a'   '0'
  'GO:0016740'    [2]    [2]    'b'   '0'
  'GO:0006412'    [2]    [2]    'b'   '1'
  'GO:0016787'    [2]    [3]    'c'   '0'
  'GO:0006810'    [2]    [4]    'd'   '0'
  'GO:0016787'    [3]    [3]    'c'   '1'
  'GO:0004672'    [3]    [3]    'c'   '2'
  'GO:0016779'    [3]    [3]    'c'   '3'
  'GO:0005215'    [3]    [3]    'c'   '4'
  'GO:0006810'    [3]    [4]    'd'   '1'
  'GO:0004386'    [3]    [4]    'd'   '2'
  'GO:0003774'    [3]    [4]    'd'   '3'
  'GO:0016298'    [3]    [4]    'd'   '4'
  'GO:0016192'    [3]    [5]    'e'   '0'
  'GO:0006412'    [3]    [2]    'b'   '2'
  'GO:0005215'    [3]    [3]    'c'   '5'
  'GO:0006810'    [4]    [4]    'd'   '5'
  'GO:0004386'    [4]    [4]    'd'   '6'

我尝试了以下代码,但无论如何它都不起作用:

x3=[];  % for saving the resulted numbers 
z=0:length(GO);  % will take the numbers from this matrix
z=z';
 for j=1:length(num2alph)
     for k=1:length(GO)
 for i=1:length(GO)
         if isequal(GO{i,4},num2alph{j})
                   x3{i}=z(k);
    else
     end
     end
     end
 end
   x3=x3';
   GO1=[GO x3];

其中 cellarray num2alph (它将与 GO 数组的第四列进行比较以构建编号列)是:

  'a'          
  'b'        
  'c'    
  'd'   
  'e'    
  'f'    
  'g'   
  'h'   
  'i'    
  'j'    
  'k'  

我还需要将最后两列相互映射到同一个单元格中,例如:

         'a'   '0'  ===>  a0
         'b'   '2'  ===>  b2

任何建议

谢谢

4

2 回答 2

3

这应该可以解决问题:

un = unique(GO(:,4));

results = zeros(size(GO(:,4)));
for ii = 1:numel(un)

    inds = strcmp(GO(:,4), un(ii));
    count = max(0, cumsum(inds)-1);

    results(inds) = count(inds);
end


GO = [GO  num2cell(results)]
于 2012-10-31T10:42:02.160 回答
2

cellhist,一个用户定义的函数,在这里真的可以成为你的朋友。它似乎可以完全解决您的需求。

于 2012-10-31T10:09:47.417 回答