我应该如何在 MATLAB 中执行分箱和平均?
我正在尝试执行分箱平均值。我正在使用代码:
Avg = mean(reshape(a,300,144,27));
AvgF = squeeze(Avg);
最后一行摆脱了单例维度。
可以看出,我的平均分超过了 300 分。它工作得很好,除了当我的总点数不等于 144*300 的倍数时。
即使总点数不是 144*300 的倍数,有什么方法可以使这种分箱平均值起作用吗?
编辑:如果我的问题听起来令人困惑,我很抱歉。为了澄清...
我有一个包含 43200 行和 27 列的文件。我通过一次分箱 300 行进行平均,这意味着最终我留下了一个大小为 144×27 的矩阵。
我上面写的代码仅当我正好有 43200 行时才有效。在某些情况下,我有 43199、43194 等。当我的总行数是 300(bin 大小)的倍数时,重塑函数就会起作用。当我的总行数不是 300 的倍数时,有没有办法让这个分箱平均值起作用?
I am trying to perform a binning average. I am using the code:
Avg = mean(reshape(a,300,144,27));
AvgF = squeeze(Avg);
The last line gets rid of singleton dimensions.
So as can be seen I am averaging over 300 points. It works fine except for times when I have a total number of points not equal to a multiple of 144*300.
Is there any way to make this binning average work even when the total number of points is not a multiple of 144*300?
EDIT: Sorry if my question sounded confusing. To clarify...
I have a file with 43200 rows and 27 columns. I am averaging by binning 300 rows at a time, which means in the end I am left with a matrix of size 144-by-27.
My code as I wrote it above works only when I have exactly 43200 rows. In some cases I have 43199, 43194, etc.. The reshape function works when I have a total number of rows that is a multiple of 300 (the bin size). Is there a way to make this binning average work when my total number of rows is not a multiple of 300?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我现在更好地理解这个问题了...
如果
a
是从文件中读取的数据(大小为 N-by-27,其中 N 理想为 43,200),那么我想你会想要执行以下操作:这将删除点,使得
a
中的行数将是 300 的倍数。然后你的重塑和平均值应该可以工作。请注意,我在调用 RESHAPE,它可以计算出列数应该是多少。I think I understand the problem better now...
If
a
is the data read from your file (of size N-by-27, where N is ideally 43,200), then I think you would want to do the following:This will remove points such that the number of rows in
a
will be a multiple of 300. Then your reshape and average should work. Note that I use[]
in the call to RESHAPE, which lets it figure out what the number of column should be.