SCALEBAR creates a scalebar on an axes
SCALEBAR(PARAMETER, VALUE, ...)
SCALEBAR(HAXES, PARAMETER, VALUE, ...)
H = SCALEBAR(...)
Draws a scalebar on the axes and returns handle to the scalebar. The DataAspectRatio property of the axes must be set to [1 1 1] and the view must be in 2D. All parameters are optional (note the default values below). SCALEBAR OFF deletes the current scalebar.
hAxes: handle to the axes (defaults to current axes)
ScaleLength: length to show (in data units) (defaults to ~10% of the x-axis limit range)
Location: location of the scalebar. Possible values are
[x y] data coordinates
Colour: colour of scalebar in 1x3 RGB array (default is [0 0 0])
Bold: draw with bold text and linewidth=2. True or false(default)
Unit: string containing units e.g. 'mm'
Amanda (2020). Scale bar for 2D axes (https://www.mathworks.com/matlabcentral/fileexchange/25799-scale-bar-for-2d-axes), MATLAB Central File Exchange. Retrieved .
Works as described. I've found that this works best if you use "axis equal" before you call the function
Can you add a function that I can modify the number of scale bar? Sometimes, the number of your scale bar show is not correct and the actual value should be another value, therefore I could edit the scale bar and make it more accurate.
I mean that the number of your scale bar shows sometimes is not in the same coordinates.
It depends on the function "range" which requires the appropriate toolbox.
As range is a very simple function, it would be useful to remove this dependency, such that everyone can use it directly.
I get a "Undefined function 'range' for input arguments of type 'double'." error
The fact that this function depends on a data aspect ratio of [1,1,1] makes its applications quite limited for actual presentation of signals.
Hi, thanks for the very useful code. Is there a way to get the scalebar in the foreground? Currently my surf overlaps the scalebar.
Very sorry for the much belated response. I've incorporated your suggestion into the code and it now has the option for a unit string.
Thank you for this useful function!
However it would be nice to input or assign a physical unit in order to clarify what physical quantity the scalebar refers to.
Do you think it would be possible to add a physical unit as a string parameter to the scalebar.m function?
Useful and simple! Thanks very much
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!