【问题标题】:Can anyone help me where I am making mistake in my matlab programming? [closed]任何人都可以帮助我在我的 matlab 编程中出错的地方吗? [关闭]
【发布时间】:2016-07-19 11:14:10
【问题描述】:

这个问题是关于使用 matlab 对数据进行分箱的。我有两个数据集。在一个数据集中,我有 x(代表速度)和 y(代表功率)值,我现在在该计算的帮助下,将它们合并并计算平均 std、edge 和 h 值(参见代码),我想识别并传递我的传入数据(在代码中,这是新数据)到它们所属的特定bin(我已经准备好在下面给出的代码中计算出来),。在下面的代码中,newdata 将包含与 bin 匹配的新数据集。请帮助我在哪里出错或修改它我收到以下错误:

Error using  > 
Matrix dimensions must agree.
Error in Binning_Online (line 23)
      newdatabin=find(newdata>binEdges,1,'last'); %this is the bin number where the new data goes in

代码:

x= load speed;
y= load power;
newdata= load new_speed;
topEdge = 20; % upper limit
botEdge = 5;  % lower limit
numBins = 40; % define number of bins 
[N,edges,bins] = histcounts(y_vector,numBins);
Pow_means = [];   speed_means = [];
for n = 1:numBins;
   Pow_means(n,1) = mean(x_vector(bins==n,1));  % for each bins mean value  calculation.
   speed_means(n,1) = mean(y_vector(bins==n,1));  % for each bins mean value calculation.
   pow_std(n,1) = std(x_vector(bins==n,1));       % for Standard deviation calculation
    binEdges = linspace(botEdge, topEdge, numBins+1);

   newdatabin= find(newdata>binedges,1,'last'); %this is the bin number where the new data goes in
   h(newdatabin)=h(newdatabin)+1;

end

【问题讨论】:

  • 问题是什么?
  • 为什么不写错误信息?
  • @giosans 这是我得到的错误:使用错误 > 矩阵尺寸必须一致。 Binning_Online 中的错误(第 23 行)newdatabin=find(newdata>binEdges,1,'last'); %这是新数据进入的bin号
  • @user4759923 如果您无法理解我的问题,我深表歉意。在这个程序中,使用 binning 方法我的目的是识别传入点属于哪个 bin 或如何识别传入数据点属于哪个 bin 组?希望对你有帮助
  • 只是表示数组newdata 的大小与binedges 的大小不同。

标签: matlab binning


【解决方案1】:

正如其他人在 cmets 中指出的那样,错误只是指出 newdatasize 不同 binedges,因此执行 newdata > binedges 会产生错误。

我的猜测是这条线

binEdges = linspace(botEdge, topEdge, numBins+1)

应该是

binEdges = linspace(botEdge, topEdge, numBins)

假设您的 newdata 数组的长度为 numBins

如果该假设不成立,那么您的问题是您任意设置了与newdata 的长度不对应的箱数。 您应该从数据中获取数字,而不是使用 幻数。 (即,而不是 numbins = 40 也许你应该做 numbins = length(newdata)

【讨论】:

    猜你喜欢
    • 2015-03-15
    • 1970-01-01
    • 2014-01-25
    • 2012-11-30
    • 2013-06-29
    • 2022-11-23
    • 1970-01-01
    • 2020-11-03
    • 2021-10-27
    相关资源
    最近更新 更多