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

4 vues (au cours des 30 derniers jours)
JM
JM le 5 Juin 2018
Modifié(e) : Robert U le 7 Juin 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?

Réponses (1)

Robert U
Robert U le 6 Juin 2018
Modifié(e) : Robert U le 7 Juin 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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by