how to use multiple function like mean and sum in cellfun at same time?

3 ビュー (過去 30 日間)
Harsh Patel
Harsh Patel 2018 年 10 月 9 日
コメント済み: Harsh Patel 2018 年 10 月 9 日
Hi, i have a 30x1 cell array with nx4 cell. I want to perform mean on 2nd and 3rd column of nx4 and find sum of 4th column of nx4. i tried using B = cellfun(@mean,A,'UniformOutput',false); but it gave me mean for all columns in nx4.

回答 (1 件)

OCDER
OCDER 2018 年 10 月 9 日
B = cellfun(@(x) [mean(x(:, 2:3), 1) sum(x(:, 4), 1)], A, 'UniformOutput', false);
you'll get a 30x1 cell containing a 1x3 matrix in each cell of
[mean of 2nd column, mean of 3rd column, sum of 4th column]

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by