필터 지우기
필터 지우기

What is the need to add or subtract offset?

조회 수: 7 (최근 30일)
mounika siripurapu
mounika siripurapu 2016년 3월 6일
댓글: mounika siripurapu 2016년 3월 8일
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by