本文介绍了Matlab如何对时间范围进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下几次
1.1
1.15
1.19
1.32
1.69
2.12
2.36
2.86
3.25
3.67
3.77
3.91
...
我希望MALTAB读取时间并将数字存储到数组中,其中数组1将在1-2秒内出现一次.阵列2将为2-3秒,依此类推.
And I would like MALTAB to read the times and store the numbers into arrays where array 1 would be for times in 1-2 seconds. Array 2 would be 2-3 seconds and so on.
在此先感谢您提供的帮助/建议
Thanks in advance for any help/advice given
推荐答案
您可以使用 accumarray
将这些数组存储为单元格数组的单元格,就像这样-
You could use accumarray
to have those arrays stored as cells of a cell array, like so -
groups = accumarray(floor(timeseries),timeseries,[],@(x){x})
样品运行-
>> timeseries
timeseries =
1.1
1.15
1.19
1.32
1.69
2.12
2.36
2.86
3.25
3.67
3.77
3.91
>> groups = accumarray(floor(timeseries),timeseries,[],@(x){x});
>> celldisp(groups) %// Display cells of output
groups{1} =
1.1
1.15
1.19
1.32
1.69
groups{2} =
2.12
2.36
2.86
groups{3} =
3.25
3.67
3.77
3.91
这篇关于Matlab如何对时间范围进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!