Averaging in a cell array

조회 수: 1 (최근 30일)
avantika . 2014년 9월 11일
댓글: Andrei Bobrov . 2014년 9월 12일
I have a cell array named data (4856x24). The data looks as follows
I want to write a function that averages out the values in each row for positive emotions (Happy,Romantic,Devotional,Calm) and negative emotions(Angry,Longing,Sad,Tensed).The averaged out value column names should be positive and negative respectively. Can anyone pls help. Thanks in advance.
  댓글 수: 2
avantika 2014년 9월 12일
편집: avantika 님. 2014년 9월 12일
I am using matlab 2013a.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 9월 11일
t1 = ~cellfun('isempty',regexp(data(1,:),'Happy|Romantic|Devotional|Calm'));
t2 = ~cellfun('isempty',regexp(data(1,:),'Angry|Longing|Sad|Tensed'));
out = [data(1,:);cell(1,size(data,2))];
out(2,t1) = num2cell(mean(cell2mat(data(2:end,t1))));
out(2,t2) = num2cell(-mean(cell2mat(data(2:end,t2))));
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2014년 9월 12일
Hi Avantika! I beg to fulfill the request by Sean, he will show us a more better solution with table array.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 9월 11일
편집: Sean de Wolski 님. 2014년 9월 11일
If you convert that to a table (cell2table) and covert the feelings to a categorical, you can then use grpstats and varfun to do this for you, grouping by whatever you want.
If you post the mat file (as a zip) I can help you through these steps, it'll be much simpler and easier to understand than regular expressions/cellfun.


Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by