フィルターのクリア

Summing matrices in cell arrays within a certain range

3 ビュー (過去 30 日間)
A. Wozniak
A. Wozniak 2017 年 9 月 20 日
コメント済み: A. Wozniak 2017 年 9 月 20 日
Hi, I would like to compute the sum from different cells in an array, plus within the certain range:
d1=FFT.mBSL{1, i, i0}(min(Freq.delta):max(Freq.delta));
d2=FFT.mBSL{2, i, i0}(min(Freq.delta):max(Freq.delta));
d3=FFT.mBSL{3, i, i0}(min(Freq.delta):max(Freq.delta));
md = mean((d1+d2+d3)/3,1);
But when I try to achieve the same in a more elegant way, using cellfun, I have these errors:
s = cellfun(@sum , FFT.mBSL(:, i, i0)(min(Freq.delta):max(Freq.delta)));
Error: ()-indexing must appear last in an index expression.
or
s = cellfun(@sum , FFT.mBSL{:, i, i0}(min(Freq.delta):max(Freq.delta)))
Bad cell reference operation.
My question is, how using @sum I can choose the range of frequencies. Thanks in advance for help.

採用された回答

Guillaume
Guillaume 2017 年 9 月 20 日
cellfun apply the same operation on each element of the cell array and returns an output for each of these. Therefore, it cannot be used to sum together these elements. What you can use cellfun for is filtering the matrices in each cells. The sum would have to be done afterwards:
filteredarrays = cellfun(@(arr) arr(min(Freq.delta):max(Freq.delta)), FFT.mBSL(:, i, i0), 'UniformOutput', false);
higherdim = ndims(filteredarrays{1}) + 1; %higher dimension for concatenation / sum / mean
filteredarrays = cat(higherdim, filteredarrays{:}); %concatenate all arrays in higher dimension so that they can be averaged
md = mean(mean(filteredarrays, higherdim), 1);
  1 件のコメント
A. Wozniak
A. Wozniak 2017 年 9 月 20 日
Thank you! Works as I wanted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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