x値の密度に応じてサイズが異なるビンを使用したいようです。以前の投稿への回答のように関数 HISTC を引き続き使用できると思いますが、別のエッジのセットを与えるだけで済みます。
これがまさにあなたが望むものかどうかはわかりませんが、ここに 1 つの提案があります。x 軸を 70 の等間隔のグループに分割する代わりに、並べ替えられた x データを 70 の等間隔のグループに分割し、エッジの値を決定します。このコードは機能するはずだと思います:
% Start by assuming x and y are vectors of data:
nBins = 70;
nValues = length(x);
[xsort,index] = sort(x); % Sort x in ascending order
ysort = y(index); % Sort y the same way as x
binEdges = [xsort(1:ceil(nValues/nBins):nValues) xsort(nValues)+1];
% Bin the data and get the averages as in previous post (using ysort instead of y):
[h,whichBin] = histc(xsort,binEdges);
for i = 1:nBins
flagBinMembers = (whichBin == i);
binMembers = ysort(flagBinMembers);
binMean(i) = mean(binMembers);
end
これにより、データ密度に応じてサイズが異なるビンが得られます。
更新: 別のバージョン...
いくつかのコメントの後、私が思いついた別のアイデアがあります。このコードでは、x 内の隣接するデータ ポイント間の差のしきい値 (maxDelta) を設定します。maxDelta 以上の量でより大きな隣人と異なる x 値は、強制的に独自のビンに入れられます (すべて孤独によって)。nBins の値を引き続き選択しますが、展開されたポイントが独自のビンに追いやられると、ビンの最終的な数はこの値よりも大きくなります。
% Start by assuming x and y are vectors of data:
maxDelta = 10; % Or whatever suits your data set!
nBins = 70;
nValues = length(x);
[xsort,index] = sort(x); % Sort x in ascending order
ysort = y(index); % Sort y the same way as x
% Create bin edges:
edgeIndex = false(1,nValues);
edgeIndex(1:ceil(nValues/nBins):nValues) = true;
edgeIndex = edgeIndex | ([0 diff(xsort)] >= maxDelta);
nBins = sum(edgeIndex);
binEdges = [xsort(edgeIndex) xsort(nValues)+1];
% Bin the data and get the y averages:
[h,whichBin] = histc(xsort,binEdges);
for i = 1:nBins
flagBinMembers = (whichBin == i);
binMembers = ysort(flagBinMembers);
binMean(i) = mean(binMembers);
end
いくつかの小さなサンプル データ セットでこれをテストしたところ、本来の動作をしているようです。うまくいけば、それが含まれているものは何でも、あなたのデータセットでもうまくいくでしょう! =)