ruler2num
将数据从特定的标尺转换为数值数据
说明
示例
将日期值转换为等效的数值
将日期值转换为等效的数值,以便设置文本对象的 Position
属性。
创建 x 轴为日期值的绘图。为第四个数据点添加文本说明,并返回文本对象。
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');
通过设置文本对象的 Position
属性,将文本的位置更改到第六个数据点。由于 Position
属性只接受数值,因此需要将第六个数据点的日期时间值转换为等效的数值。
ax = gca; x6 = ruler2num(t(6),ax.XAxis); txt.Position = [x6 y(6)];
输入参数
data
— 输入数组
标量 | 向量 | 矩阵
输入数组,指定为标量、向量或矩阵。如果 data
已经是数值,则输出 num
等于输入 data
。
ruler
— 标尺
DurationRuler
对象 | DatetimeRuler
对象 | NumericRuler
对象 | CategoricalRuler
对象 | GeographicRuler
对象
与输入数据相关联的标尺,指定为以下标尺对象类型之一:
DurationRuler
对象 - 将data
中的持续时间值转换为数值。DatetimeRuler
对象 - 将data
中的日期时间值转换为数值。要控制如何将日期时间值转换为double
值,请将标尺的ReferenceDate
属性设置为具有所需时区的日期时间值。NumericRuler
对象 - 大多数情况下不转换。但是,如果输入数据不是数值,则输出是num = full(double(data))
。CategoricalRuler
对象 - 将data
中的分类值转换为数值。要控制类别的顺序,请设置标尺的Categories
属性。GeographicRuler
对象 - 不转换。输出等于输入。
将标尺对象指定为 Axes
对象的 XAxis
、YAxis
或 ZAxis
属性。例如:
ax = gca; num = ruler2num(data,ax.XAxis)
版本历史记录
在 R2016b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)