binning - Can anyone help me where I am making mistake in my matlab programming? -
this question binning data using matlab. have 2 data sets. in 1 data sets have x (represent speed) , y(represent power) value binned , calculated mean std,edge , h value(see code) of calculation want identify , pass incoming data(here in code 1 newdata) particular bin in belong(which ready calculated here in given below code), . in code below, newdata contain new data sets matching bin. please me making mistake or modify , getting following error :
error using > matrix dimensions must agree. error in binning_online (line 23) newdatabin=find(newdata>binedges,1,'last'); %this bin number new data goes in
code:
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 = []; n = 1:numbins; pow_means(n,1) = mean(x_vector(bins==n,1)); % each bins mean value calculation. speed_means(n,1) = mean(y_vector(bins==n,1)); % each bins mean value calculation. pow_std(n,1) = std(x_vector(bins==n,1)); % standard deviation calculation binedges = linspace(botedge, topedge, numbins+1); newdatabin= find(newdata>binedges,1,'last'); %this bin number new data goes in h(newdatabin)=h(newdatabin)+1; end
as others have pointed out in comments, error states newdata
of different size
binedges
, , therefore performing newdata > binedges
produces error.
my guess line
binedges = linspace(botedge, topedge, numbins+1)
should be
binedges = linspace(botedge, topedge, numbins)
on assumption newdata
array of length numbins
if assumption false, problem arbitrarily setting number of bins not correspond length of newdata
. instead of using magic numbers should obtaining numbers data. (i.e. instead of numbins = 40
maybe should doing numbins = length(newdata)
)
Comments
Post a Comment