# Trying to calculate variance in cells nested within a 1x9 cell

3 views (last 30 days)
JM on 5 Jun 2018
Edited: Robert U on 7 Jun 2018
Currently I have a variable that is a 1x9 cell (lets call it X). Within X, there are a variety of different sized nested cells, such as 1700x1, 1500x1, etc).
I want to create a new variable that contains the variance for each of those 9 cells in its own 1x9 array.
I've been trying to work out the issue myself, and so far I've run into an issue calculating the variance for just 1 column in X.
A = cellfun(@var,X{1,1}) --- However, this gives me a very long list of values the same height as the column I am working with. For instance, it will output 1700 values for variance, and I'm not sure where exactly it is getting this numbers from.
Hopefully this makes sense, does anyone have any suggestions?

Robert U on 6 Jun 2018
Edited: Robert U on 7 Jun 2018
Hello Jonathan Marchetto:
I generated data that should fit your description:
X = {};
for ik = 1:9
X{ik} = num2cell(rand(1700-200*(ik-1),1));
end
From what you describe this should work to calculate variance for each sub-cell values:
A = cellfun(@(cIn) var(cell2mat(cIn)),X);
Kind regards,
Robert