I have combined the folowing posts how to count unique elements of a cell in matlab?
Finding which letter has maximal occurence
to be able to find max occurance with penalty. i.e. cell = 'a' 'b' 'a' 'c' 'a' 'a' 'e' penalty= [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
i just need a hint maybe i am missing something you can ease things on me thanks
need to add something on the last line but how?
enter code here str= num2cell(Allquants{p});
matchcell ={'a','b','c','d','e'};
[~,index] =ismember(str,matchcell);
count = accumarray(index(:),1,[numel(matchcell) 1]);
Now the code is:
plaincount = accumarray(index(:),1,[numel(matchcell) 1]);
count = accumarray(index(:),penalties{p}{r},[numel(matchcell) 1],@sum);
Maybe it should be outside the loop? yes {r} should be removed
You need to put the penalties into the second argument of
accumarray
, since it is these values that will get summed up (note that penalty needs to be numeric, so you may have to callcell2mat
):