ruler2num
Convert data from specific ruler to numeric data
Description
Examples
Convert Date Value to Equivalent Numeric Value
Convert a date value to the equivalent numeric value in order to set the Position
property of a text object.
Create a plot with dates along the x-axis. Add a text description to the fourth data point and return the text object.
t = datetime(2015,1,1:10); y = [.2 .3 .5 .2 .8 .2 .3 .1 .3 .4]; plot(t,y,'-o') txt = text(t(4),y(4),'My text');
Change the position of the text to the sixth data point by setting the Position
property of the text object. Since the Position
property accepts only numeric values, convert the datetime value at the sixth data point to the equivalent numeric value.
ax = gca; x6 = ruler2num(t(6),ax.XAxis); txt.Position = [x6 y(6)];
Input Arguments
data
— Input array
scalar | vector | matrix
Input array, specified as a scalar, vector, or matrix. If
data
is already numeric, then the output
num
is equal to the input
data
.
ruler
— Ruler
DurationRuler
object | DatetimeRuler
object | NumericRuler
object | CategoricalRuler
object | GeographicRuler
object
Ruler associated with the input data, specified as one of these types of ruler objects:
DurationRuler
object — Convert the duration values indata
to numeric values.DatetimeRuler
object — Convert the datetime values indata
to numeric values. To control how datetime values are converted todouble
values, set theReferenceDate
property of the ruler to a datetime value with the desired time zone.NumericRuler
object — No conversion in most cases. However, if the input data is not numeric, then the output isnum = full(double(data))
.CategoricalRuler
object — Convert the categorical values indata
to numeric values. To control the order of the categories, set theCategories
property of the ruler.GeographicRuler
object — No conversion. The output is equal to the input.
Specify the ruler object as the XAxis
,
YAxis
, or ZAxis
property of
the Axes
object. For example:
ax = gca; num = ruler2num(data,ax.XAxis)
Version History
Introduced in R2016b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)