まず、多次元構造を定義するつもりだと思います:
a(1).field1=[1:5];
a(2).field1=[1:6];
a(1).field2=[2:8];
a(2).field2=[2:9];
(中かっこの代わりに丸かっこに注意してください。中かっこを使用すると、2 つstruct
の を含むセル配列が得られます)。今、あなたが求める値:
max_mean = cellfun(@(x)[max(x) mean(x)], {a.field1}, 'UniformOutput', false);
これを行うと、 in の最大値と平均値、およびa(1).field1
inmax_mean{1}
の最大値と平均値が得a(2).field1
られmax_mean{2}
ます。
cellfun
上記を別のフィールドにネストすることで、すべてのフィールドに対してこれを行うことができますcellfun
。
max_means = cellfun(@(x) ...
cellfun(@(y)[max(y) mean(y)], {a.(x)}, 'UniformOutput', false), ...
fieldnames(a), 'UniformOutput', false);
となることによって
max_means{1}{1} % will give you the max's and means of a(1).field1
max_means{1}{2} % will give you the max's and means of a(2).field1
max_means{2}{1} % will give you the max's and means of a(1).field2
max_means{2}{2} % will give you the max's and means of a(2).field2
ニーズに合ったものが見つかるまで、これらの関数を試してみてください。