时间步长之间的计算装置,用于在MATLAB给定持续时间的值 [英] Compute means between time steps for given duration values in MATLAB
问题描述
例如,我有5个步骤,时间和持续时间值:
For example, I have 5 time steps and a duration value:
TimeSteps = [4, 5, 6, 7, 8, 10, 11, 12, 14, 15, 16];
Duration = [5, 3, 3];
我想自动生成对于每个持续时间的时间步长之间的装置。在这种情况下,结果是这样的:
I want to automatically generate the means between the time steps for every duration. In this case, the result would look like this:
Result = [mean([4, 5, 6, 7, 8]), mean([10, 11, 12]), mean([14, 15, 16])];
这会导致:
Result = [6, 11, 15];
我有一个474x1时间矢量,所以我需要你完成这项。如果有人可以帮助,这将是巨大的。谢谢。
I have a 474x1 duration vector, so I need to automatize this. If anyone can help, it would be great. Thank you.
推荐答案
您需要将的意思是
功能应用到你的时间步<的一个分区/ code>是在
持续时间
尺寸:
You need to apply the mean
function to a partition of your TimeSteps
that has the sizes in Duration
:
Partition = mat2cell(TimeSteps, 1, Duration);
Result = cellfun(@mean, Partition)
如果你是单行的粉丝:
Result = cellfun(@mean, mat2cell(TimeSteps, 1, Duration));
的注:的请您考虑这个解决方案是张贴行向量;修改 mat2cell
要求的列向量。
Note: Please take in account that this solution is posted for row vectors; change the mat2cell
call for column vectors.
这篇关于时间步长之间的计算装置,用于在MATLAB给定持续时间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!