Mean of matrices in cell array

1 view (last 30 days)
Ian Loveless
Ian Loveless on 2 Oct 2018
Commented: Ian Loveless on 2 Oct 2018
I have a 100x40 cell array, each cell contains a 46x2 double, which is the score output from classifiers: knn, treebagger, svm. I am trying to make ROC curves from the scores, but I need to take the mean of the elements in each array. Basically, the 100 is the number of iterations for which I ran my code and the 40 is the number of feature sizes selected. The 46 is the number of test points I used. I need the mean of the score for each sample size. I am relatively new to MATLAB and am not sure where to start. I read through other posts and found some help, but cannot seem to apply it to my issue. The code I tried is:
catscore=mean(cat(2,scorepofknn15{:}),2);
which did not produce the desired result. Any help or suggestions would be greatly appreciated.

Answers (1)

Sandra Preaux
Sandra Preaux on 2 Oct 2018
I'm not sure from your question if you are trying for catscores to be 100x40 or 1x40. So I'll show both. If you want 100x40 (one average for each run of each feature size) then use this loop
xm=zeros(size(scorepofknn));
for ii=1:size(scorepofknn15,1)
for jj=1:size(scorepofknn15,2)
xm(ii,jj)=mean(scorepofknn15{ii,jj});
end
end
If you want to cat all runs for the same feature size together use this loop
xm=zeros(1,size(scorepofknn15,2));
for ii=1:size(scorepofknn15,2)
xm(1,ii)=mean([x{:,ii}]);
end
  1 Comment
Ian Loveless
Ian Loveless on 2 Oct 2018
Thank you for your reply. I will try and clarify my hope a little more. I am hoping that my final result will be a 1x40, where each cell is a 46x2 that is a mean of the score for each point. If that still is not clear, I can attempt to clarify further.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!