merging columns in cellarray

Hi everybody! I have a question: I have a cell array with 3 columns, in the first the word occurance, in the second the frequency of this word in the text 1, in the third the occurance of the word in text 2.
for example:
  • [] 0,007 0
  • [] 0 0,002
  • 'a' 0,015 0
  • 'a' 0 0,016
  • 'aa' 0 4,77e-06
  • 'abdomen' 1,90e-05 0
  • 'abdomen' 0 1,43e-05
  • 'aberrant' 6,33e-05 0
  • 'aberrant' 0 4,77e-05
What I would get is:
  • [] 0,007 0,002
  • 'a' 0,015 0,016
  • 'aa' 0 4,77e-06
  • 'abdomen' 1,90e-05 1,43e-05
  • 'aberrant' 6,33e-05 4,77e-05
So I want to delete duplicates and to merge the two probabilities.. any suggestions??
Thank you very much!

댓글 수: 2

Walter Roberson
Walter Roberson 2012년 5월 30일
how is the new word occurrence to be calculated ?
ilaria
ilaria 2012년 5월 30일
that's just the relative frequency of that word in the text.. but this is already calculated.. now I have just to "make an unique" to merge together the same words, but also the probability..
so for example:
'a' 0,015 0
'a' 0 0,016
a is the same symbols, and I know that in the first text has a frequency of 0.015 in the second 0.016..I want to obtain:
'a' 0.015 0.016

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 30일

0 개 추천

[uniquewords, junk, wordidx] = unique(YourCell(:,1));
mergedprobs = accumarray( wordidx(:), cell2mat(YourCell(:,3)) ); %totals by default
mergedoccur = accumarray( wordidx(:), cell2mat(YourCell(:,2)) ); %totals by default
NewCell = [uniquewords(:), num2cell(mergedoccur(:)), num2cell(mergedprobs(:)) );

댓글 수: 1

ilaria
ilaria 2012년 5월 30일
Thank you! It is exactly what I was looking for!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by