时间序列的单元格数组中的数据总和(结束) [英] Sum of Data(end) in a cell array of timeseries
本文介绍了时间序列的单元格数组中的数据总和(结束)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下代码:
% Generate some random data
n = 10;
A = cell(n, 1);
for i=1:n
A{i} = timeseries;
A{i}.Data = rand(100, 1);
A{i}.Time = 1:100;
end
我想在不显式编写for
循环的情况下计算Data(end)
的总和.有没有一种聪明的方法可以在一行中的所有单元格中选择Data(end)
? A{:}.Data(end)
不起作用.
I would like to make the sum of Data(end)
without explicitly writing a for
loop. Is there a smart way to select Data(end)
in all cells in a single line? A{:}.Data(end)
does not work.
推荐答案
You can do it with cellfun
but that is essentially just a for loop wrapped up:
cellfun(@(x) x.Data(end), A)
这篇关于时间序列的单元格数组中的数据总和(结束)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文