What is the need to add or subtract offset?

4 ビュー (過去 30 日間)
mounika siripurapu
mounika siripurapu 2016 年 3 月 6 日
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
mounika siripurapu 2016 年 3 月 6 日
編集済み: 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
mounika siripurapu 2016 年 3 月 8 日
<<
>>This the output I got using offset
mounika siripurapu
mounika siripurapu 2016 年 3 月 8 日
This is the output without offset. Now can you explain me the need for using offset?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by