Getting mean row vector from a cell array of row vectors of the same size
Show older comments
Hi there,
I have a cell array of 1x60, each containing a double/row vector of 1x256 - each of these a histogram of an image of values from 0 to 255.
I need to find the mean row vector/histogram across all 60 of these images i.e. the average of cells 1-256 across all 60. I understand the logic but don't know how to code it.
Any help would be very much appreciated. Thank you.
Accepted Answer
More Answers (1)
Allen
on 26 May 2021
It is not entire clear to me what you are trying to average. However, if I am understanding correctly, the following example attempts to duplicate your 1x60 cell-array with 1x256 numerical arrays, where each numerical array contains a randomly assigned value from 0 to 255 for each element. I then determine the average of all values in each 1x256 numerical array and since there are 60 elements in the cell-array, the end result is a 1x60 numerical array. If this not what you are looking for please provide more details and include your an example of your initial data and a few snippets of code that you have already attempted.
% Attempts to duplicate your datasets as elements in a cell-array (each cell-array element is a 1x256 numerical array)
C = arrayfun(@(x) randi([0,255],[1,256]),1:60,'un',0);
% Calculates the overall average for each element in the cell-array
avg = cellfun(@mean,C);
Categories
Find more on Numeric Types 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!