对细胞生成字母添加惩罚

时间:2012-02-29 10:44:48

标签: matlab

我已将以下帖子合并在一起 how to count unique elements of a cell in matlab?

Finding which letter has maximal occurence

能够找到惩罚的最大发生率。 即cell ='a''b''''c''a''a''e'      惩罚= [5] [2] [4] [2] [5] [1] [0]

 letterWeight= [1*5] [1*2] .....

now letter count will be 'a'[5+4+5+1]
                         'b'[2]
                         'c'[2]
                         'e'[0]
now maxcount= as done in max occurance

我只需要一个提示,也许我错过了一些你可以放松的事情,谢谢

需要在最后一行添加一些内容但是如何?

enter code here str= num2cell(Allquants{p});
                matchcell ={'a','b','c','d','e'};
                [~,index] =ismember(str,matchcell);
                count = accumarray(index(:),1,[numel(matchcell)  1]);

现在代码是:

      plaincount = accumarray(index(:),1,[numel(matchcell)  1]);
      count = accumarray(index(:),penalties{p}{r},[numel(matchcell)  1],@sum); 

也许它应该在循环之外?应删除是{r}

1 个答案:

答案 0 :(得分:1)

你需要将惩罚放入accumarray的第二个参数,因为这些值会被总结(注意惩罚需要是数字,所以你可能需要调用cell2mat ):

count = accumarray(index(:),penalties,[numel(matchcell)  1],@sum);