MATLAB: Mean percentage corresponding to x binned

foor-loopmean percentage

i recieve this error while i was trying to calculate mean percentage of (y) corresponding to binned x:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1.
Error in dose_meanvs_distance (line 12) Mean_perc (counter,1) = (Mean_dose_interval/size(interval,1))*100;
this is part of my code:
counter = 1
for m= (min(x)):0.5 : (max(x))
interval = x > m & x < m+0.5;% after running the loop it keeps the run results
distance(counter,1) = mean(x(interval));
Mean_dose_interval(counter,1) = mean(y(interval));
Mean_perc (counter,1) = (Mean_dose_interval/size(interval,1))*100;
err (counter,1) = std(y(interval));
counter=counter+1;
end

Best Answer

It looks like Mean_dose_interval is 2-dimensional and you're assigning a 2D array to a single indexed location (ie 1D) in this line from your code:
Mean_perc (counter,1) = (Mean_dose_interval/size(interval,1))*100;
In other words, --"(Mean_dose_interval/size(interval,1))*100"-- is 2D and you're trying to put that in -- "Mean_perc (counter,1)" -- which is 1D
Here's a simpler example of the ERROR (ie, this will break)
g = [0 0];
g(1,1) = [1 2];