我还在学习如何编写循环并使用cellfun。
我有n(= 3124)个大小相等的数组:
[45x5 double]
[45x5 double]
[nx5 double]
....
数组{1,1}
1691 7858 1 735064.617361111 0.00277777777955635
1691 7958 2 735064.620138889 NaN
1691 7926 3 735064.620138889 0.000694444446708076
.....
数组{2,1}
1691 7858 1 735064.666666667 0.00138888889341615
1691 7958 2 735064.668055556 0.000694444439432118
1691 7926 3 735064.668750000 0
.....
数组{N,1}
1691 7858 1 735064.360416667 0.000694444439432118
1691 7958 2 735064.361111111 0.000694444446708076
1691 7926 3 735064.361805556 NaN
.....
我想获得一个45x5的nx5数组单元格,其中第5列的行数总和基于第4列的条件。条件是:
7307 < = values in column 4 < 7.3070e+03
我在这里找到了类似的问题:
Cellfun : How to sum each row in a cell array of matrices? Matlab
matlab - cellfun sum all elements of each cell
When and why should I use cellfun in Matlab?
Find values in a matrix and sum when found
以下是我的尝试:
for i=1:size(A,1)
for j=1:size(A{i,1},1)
if 7307 < (A{i,1}(j,4)) < 7.3070e+03
mean_A = nanmean(A{i,1}(j,5))
end
end
end
使用此代码,我只获得一个结果不是每个矩阵值的平均值的单元格。你能告诉我这个循环的主要问题是什么,或者给我一个如何在这种情况下使用cellfun的提示? 谢谢