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

2 ビュー (過去 30 日間)
JM
JM 2018 年 6 月 5 日
編集済み: Robert U 2018 年 6 月 7 日
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?

回答 (1 件)

Robert U
Robert U 2018 年 6 月 6 日
編集済み: Robert U 2018 年 6 月 7 日
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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by