MATLAB 帮助中心
本页采用了机器翻译。点击此处可查看最新英文版本。
用于将变量导出到流的数据类型
自 R2022b 起
此函数需要 Streaming Data Framework for MATLAB® Production Server™。
type = getvartype(opts)
[name,type] = getvartype(opts)
___ = getvartype(opts,selection)
当使用 opts 指定的导出选项将变量导出到事件流时,type = getvartype(opts) 返回变量的数据类型。
opts
type
示例
[name,type] = getvartype(opts) 还返回变量的名称。
name
___ = getvartype(opts,selection) 仅返回 selection 指定的变量的数据类型和可选的名称。
selection
全部折叠
假设您有一个在网络地址 kafka.host.com:9092 上运行的 Kafka® 服务器,该服务器包含主题 Triangles 和 numericTriangles。
kafka.host.com:9092
Triangles
numericTriangles
创建一个连接到 Triangles 主题的 KafkaStream 对象。
KafkaStream
inKS = kafkaStream("kafka.host.com",9092,"Triangles");
将 Triangles 主题中的事件读入时间表。通过查看第一行来预览数据。a、b 和 c 三角形边长存储为字符串。
a
b
c
tt = readtimetable(inKS); row = tt(1,:)
row = 1×3 timetable timestamp a b c ___________ ____ ____ ____ 03-Sep-2022 "15" "31" "36"
使用 detectExportOptions 从 Kafka 流对象生成 ExportOptions 对象。该函数获取用于从时间表第一行导出变量的类型。
detectExportOptions
ExportOptions
opts = detectExportOptions(inKS,row);
使用 getvartype 确认边长变量当前以字符串的形式导出到流中。
getvartype
type = getvartype(opts,["a" "b" "c"]);
type = 1×3 string array "string" "string" "string"
更新导出选项,以便将边长导出为 double 值。使用 getvartype 确认更新的选项。
double
opts = setvartype(opts,["a","b","c"],"double"); [name,type] = getvartype(opts); fprintf("%s: %s\n", [name; type])
a: double b: double c: double
连接到流以将数据导出到 numericTriangles。
outKS = kafkaStream("kafka.host.com",9092,"numericTriangles", ... ExportOptions=opts)
outKS = KafkaStream with properties: Topic: "numericTriangles" Group: "85c42e39-695d-467a-86f0-f0095792e7de" Order: EventTime Host: "kafka.host.com" Port: 9092 ConnectionTimeout: 30 RequestTimeout: 61 ImportOptions: "None" ExportOptions: "Source: string" PublishSchema: "true" WindowSize: 50 KeyVariable: "key" KeyEncoding: "utf16" KeyType: "text" KeyByteOrder: "BigEndian" BodyEncoding: "utf8" BodyFormat: "JSON" ReadLimit: "Size" TimestampResolution: "Milliseconds"
将时间表导出至新流。此流中的三角形边长为 double 类型。
writetimetable(outKS,tt);
事件流导出选项,指定为 ExportOptions 对象。
选定的变量,指定为字符向量、字符串标量、字符向量元胞数组或字符串数组。
变量名必须是 opts 对象识别的名称的子集。
示例: 'FanID'
'FanID'
示例: "FanID"
"FanID"
示例: {'FanID','vMotor'}
{'FanID','vMotor'}
示例: ["FanID" "vMotor"]
["FanID" "vMotor"]
数据类型: char | string | cell
char
string
cell
导出到流的变量的数据类型,以字符串数组的形式返回。
type 的每个元素指定流中变量的数据类型。如果指定了 selection,则返回类型的顺序与 selection 中命名的变量的顺序相匹配。否则,该顺序与在调用 detectExportOptions 时用于创建 opts 的时间表行中的变量名称的顺序相匹配。
导出到流的变量的名称,以字符串数组的形式返回。
name 的每个元素指定流中变量的名称。返回的名称的数量和顺序与 type 返回的数据类型的数量和顺序相匹配。
在 R2022b 中推出
setvartype | detectExportOptions
setvartype
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处