Mean over a multidimensionnal Cell

2 views (last 30 days)
Florian
Florian on 27 Mar 2014
Commented: Florian on 27 Mar 2014
Hi all,
I got a cell whose form is as follow :
data{number_of_file,1}(number_of_line,number_of_columns)
I'd like to average over, for instance, the first line of the first column over all files, then the second line of the first column over all files, etc.
What would you suggest ? I've tried :
for j=1:length(data{1,1}) % loop over all lines
meanP=nanmean(data{:,1}(j,1)); % loop over all files for the j line
end
But I end up with this message : Bad cell reference operation.
Thanks
Florian

Accepted Answer

A Jenkins
A Jenkins on 27 Mar 2014
You want the average of per-line of all the files? If all of the data are the same number of rows, then you can concatenate them together and average the rows in one line:
data{1,1}=rand(3,3);
data{2,1}=rand(3,3);
meanP=nanmean(horzcat(data{:,1}),2); %by row
Or by column:
meanP=nanmean(vertcat(data{:,1}),1); %by column
  1 Comment
Florian
Florian on 27 Mar 2014
Thank you, I didn't know the vertcat function, newbie ;) Florian

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!