问题描述
我有以下代码给我,但我不知道这里的逻辑是什么。这个想法,我相信,这将直方图/量化我的数据。这是代码:
输入:
x = 180 * rand(1,1000); %1000点从0到180度。
binWidth = 20; %我想binWidth是20度。
主要功能:
%------------------------------------------ -------------------------------
%计算最小的仓中心x1小于或等于x
%--------------------------------------------- ----------------------------
function [x1,b1] = computeLowerHistBin(x,binWidth)
%Bin index
bin = floor(x./binWidth - 0.5);
%bin center x1
x1 = binWidth *(bin + 0.5);
%添加2到基于1的索引
b1 = bin + 2;
end
最后,最终的量化数据:
w = 1 - (x - x1)./ binWidth
这里是我没有得到:我不明白 - 在所有 - 只是为什么 x1
是计算的方式,而且为什么/如何 w
是按照它的方式计算的。事实上,在所有的事情, w
困惑我最。我真的不明白这里的逻辑,或什么是真正的意图。将欣赏这个逻辑的详细阐释。
他正在使用 lb< = x&并分割
[ - 10,10],[10,30],[3080]中的
。 [0,180]
,40)...,[150,170],[170,190]
假设 x = 180
,则:
bin = floor(180 / 20-0.5)= floor(9-0.5)= floor (8.5)= 8;
而如果 x = 0
:
bin = floor(`0 / 20-0.5)= floor(-0.5)
分别转换为 最后, I have following code that was given to me, but I am not sure at all as to what the logic here is. The idea, I believe, is that this will histogram/quantize my data. Here is the code: The input: The main function: Finally, the final 'quantized' data: Here is what I do not get: I do not understand - at all - just why exactly He is binning with Suppose while if which respectively translate into In the end, 这篇关于不知道这是什么“直方图代码”在做MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! x1 = 20 *(8 + 0.5)= 170
和
x1 = -10
,这看起来像函数建议 lowerHistBin()
/ p>
w
只是测量 x
来自相应的下部bin x1
。注意 w
在(0,1]中, w
因此,如果x表示接近170,则 w ,并且当
x-> x1 + binWidth
/ code>将接近 1 - (170-150)/ 20 = 0
。x = 180.*rand(1,1000); %1000 points from 0 to 180 degrees.
binWidth = 20; %I want the binWidth to be 20 degrees.
% -------------------------------------------------------------------------
% Compute the closest bin center x1 that is less than or equal to x
% -------------------------------------------------------------------------
function [x1, b1] = computeLowerHistBin(x, binWidth)
% Bin index
bin = floor(x./binWidth - 0.5);
% Bin center x1
x1 = binWidth * (bin + 0.5);
% add 2 to get to 1-based indexing
b1 = bin + 2;
end
w = 1 - (x - x1)./binWidth
x1
is computed the way it is, and also why/how w
is computed the way it is. In fact, of all the things, w
confuses me the most. I literally cannot understand the logic here, or what is really intended. Would appreciate a detailed elucidation of this logic. Thanks.lb <= x < up
and splitting the interval [0,180]
in [-10,10), [10, 30), [30,40) ..., [150,170), [170,190)
.x = 180
, then:bin = floor(180/20-0.5) = floor(9-0.5) = floor(8.5) = 8;
x = 0
:bin = floor(`0/20-0.5) = floor(-0.5) = floor(-1) = -1;
x1 = 20 * (8+0.5) = 170
and x1 = -10
which seems like what the function suggests lowerHistBin()
.w
simply measures how far the point x
is from the corresponding lower bin x1
. Notice that w
is in (0,1], with w
being 1 when x = x1
and approaching 0 when x -> x1+binWidth
. So, if x say approaches 170, then w
will approach 1 - (170-150)/20 = 0
.