What is the need to add or subtract offset?
4 次查看(过去 30 天)
显示 更早的评论
Why do we add or subtract offset values while using loop functions and what does the starting and ending bins of histogram store?
2 个评论
John D'Errico
2016-3-6
You need to be more specific. For example, "offset values" is a phrase that has absolutely no meaning out of context. So, if you have a question about a specific piece of code, or a specific problem, then ask it.
As for a histogram, perhaps you just need to understand what a histogram is, and what the bins of the histogram are. For that, Google is your friend.
回答(1 个)
Walter Roberson
2016-3-6
1)
There is no real reason for writing the code with those offsets. The author happened to be thinking of the code some particular way on the day the author wrote it. The author might have had some particular idea in mind, some vision of what it represented. Or the author might have been tired. Or the author might have been under some restriction that encouraged this kind of programming. Some authors dislike temporary variables.
I would probably not usually write it that way myself. I would probably usually create temporary variables to hold the boundaries and use those. And then the question would be "why those boundaries" rather than "why add or subtract offsets". But if I was putting something together on the command line instead of thinking about code maintenance then I might use an offset.
2) What the starting and ending bins of a histogram stores depends upon the histogram function being used. Any time you are dealing with a histogram function with defined boundaries, you need to know whether the boundaries are "inclusive" or "exclusive" -- if you have boundaries A, B, C, then you might have any of several different bin relationships programmed:
A <= x < B; B <= x < C; x == C exactly; %this is what histc() uses
A <= x < B; B <= x <= C; %this is what histedges() uses
A < x <= B; B < x <= C; %potentially valid
x == A exactly; A < x <= B; B < x <= C; %potentially valid
-inf < x <= A; A < x <= B; C < x < inf; %potentially valid
-inf < x < A; A <= x < B; B <= x < C; C <= x < inf %potentially valid
-inf <= x <= A; A < x <= B; C < x <= inf; %potentially valid
-inf <= x < A; A <= x < B; B <= x < C; C <= x <= inf %potentially valid
What, exactly, the first and last bins store depends upon which of these you are using.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!