What is the need to add or subtract offset?

4 visualizaciones (últimos 30 días)
mounika siripurapu
mounika siripurapu el 6 de Mzo. de 2016
Comentada: mounika siripurapu el 8 de Mzo. de 2016
Why do we add or subtract offset values while using loop functions and what does the starting and ending bins of histogram store?
  2 comentarios
John D'Errico
John D'Errico el 6 de Mzo. de 2016
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 el 6 de Mzo. de 2016
Editada: Jan el 6 de Mzo. de 2016
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

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 6 de Mzo. de 2016
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 comentarios
mounika siripurapu
mounika siripurapu el 8 de Mzo. de 2016
<<
>>This the output I got using offset
mounika siripurapu
mounika siripurapu el 8 de Mzo. de 2016
This is the output without offset. Now can you explain me the need for using offset?

Iniciar sesión para comentar.

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by