I have a cell array c
of equal-sized arrays, i.e. size(c{n}) = [ m l ... ]
for any n
. How can I get the mean
values (averaging over the cell array index n
) for all array elements in one sweep? I thought about using cell2mat
and mean
but the former does not add another dimension but changes l
to l*n
. And looping manually of course takes like forever...
相关问题
- Extract matrix elements using a vector of column i
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- Convert Array to custom object list c#
- pick a random item from a javascript array
相关文章
- Numpy matrix of coordinates
- PHP: Can an array have an array as a key in a key-
- Accessing an array element when returning from a f
- How can I convert a PHP function's parameter l
- How to make a custom list deserializer in Gson?
- How do I append metadata to an image in Matlab?
- Recursively replace keys in an array
- React Native - Dynamic Image Source
I found an easy way to find the mean values within a Cell array on the following link: http://www.gomatlab.de/cellfun-t25114.html
May
x
be the cell. Then:If all of your arrays are the same size, it makes more sense to store them in a matrix rather than a cell array. That makes it easier to perform operations across them, like taking the mean. You can convert your data to a matrix using the functions NDIMS and CAT:
This just loops through the cell and means the array down until it is a singleton. It doesn't take that long, this is 40 million floats being meaned, takes 1 second.
If you have a Higher version of matlab, It can be done by 'cellfun' function. This can treat the cells with unequal size array.
Reference: https://groups.google.com/forum/?fromgroups=#!topic/comp.soft-sys.matlab/S_hyHxy11f0
You're on the right track. Use CELL2MAT to convert your cell array to a numerical array and then RESHAPE to construct a three dimensional matrix. You can then calculate the mean using the MEAN function with the dimension argument:
thanks for your other comments, but sometimes, it is hard to rearrange the data or change the way they are saved. For those of you who have this issue, here is the solution, Enjoy.