我有以下的时间
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秒,以此类推。
预先感谢您的帮助/建议。
发布于 2015-09-23 09:12:18
您可以使用accumarray将这些数组存储为单元格数组,如下所示-
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发布于 2015-09-23 10:43:03
让t表示输入向量。然后
t = sort(t); %// not needed if t is assured to be non-decreasing (as in the example)
result = mat2cell(t(:), diff([0; find(diff([floor(t(:)); NaN]))]));在您的示例中,这将给出
result{1} =
1.1000
1.1500
1.1900
1.3200
1.6900
result{2} =
2.1200
2.3600
2.8600
result{3} =
3.2500
3.6700
3.7700
3.9100发布于 2015-09-23 09:09:38
我不知道Matlab的确切语法,但是一种方法是在时间变量上使用一个地板函数,将它们映射到时间的整数部分,然后将具有相同楼层的函数放在同一个数组中。
https://stackoverflow.com/questions/32735305
复制相似问题