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
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.
mounika siripurapu
编辑:Jan 2016-3-6
Here is the code.
offset=15;
if i<=starti+offset
BC_diff_TD(i-starti+1) = BC_Bottom;
if i==starti+offset,
BC_diff_TD(1:i-starti+1) = BC_Top-BC_diff_TD(1:i-starti+1) ;
end
elseif i>=endi-offset,
if i==endi-offset,
to_subs = BC_Bottom;
end
BC_diff_TD(i-starti+1) = BC_Top-to_subs;
else
BC_diff_TD(i-starti+1) = BC_Top-BC_Bottom;
end
end

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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.
  2 个评论
mounika siripurapu
This is the output without offset. Now can you explain me the need for using offset?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by