text-files - 如何在 Modelica 中减去或添加 CombiTimeTable 的时间序列数据?
问题描述
我有一个用于CombiTimeTable
. 文本文件如下所示:
#1
double tab1(5,2) # comment line
0 0
1 1
2 4
3 9
4 16
第一列是时间,第二列是我的数据。我的目标是将每个数据添加到前一个数据中,从第二行开始。
model example
Modelica.Blocks.Sources.CombiTimeTable Tsink(fileName = "C:Tin.txt", tableName = "tab1", tableOnFile = true, timeScale = 60) annotation(
Placement(visible = true, transformation(origin = {-70, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
end example;
Tsink.y[1]
是表的第 2 列,但我不知道如何访问它以及如何对其执行操作。谢谢你的帮助。
解决方案
您不能在此处使用 ModelicaStandardTables 的块,这些块仅用于插值,因此不会将样本点暴露给 Modelica 模型。但是,您可以使用 Modelica 库ExternData轻松地从 CSV 文件中读取数组并对读取的数据执行所需的操作。例如,
model Example "Example model to read array and operate on it"
parameter ExternData.CSVFile dataSource(
fileName="C:/Tin.csv") "Data source"
annotation(Placement(transformation(extent={{-60,60},{-40,80}})));
parameter Integer n = 5 "Number of rows (must be known)";
parameter Real a[n,2] = dataSource.getRealArray2D(n, 2) "Array from CSV file";
parameter Real y[n - 1] = {a[i,2] + a[i + 1,2] for i in 1:n - 1} "Vector";
annotation(uses(ExternData(version="2.6.1")));
end Example;
其中 Tin.csv 是以逗号作为分隔符的 CSV 文件
0,0
1,1
2,4
3,9
4,16
推荐阅读
- python - 如何制作字典词典?
- python - 提到电报机器人时没有响应
- java - Javafx - 从 java 类更新 UI 中的进度指示器
- go - 如何更改 Go 模块路径?
- asp.net - 基于gridview数据查询时oracle最大游标问题
- javascript - 在 django 中,如何在 javascript 中使用 XMLHttpRequest 发送 json 对象
- opengl - 为什么我的场景看起来深度测试已禁用?
- json - 如何将 JSON 对象转换为图像对象?
- apache-flink - 如何将来自一个源的不同事件分配给键控流?
- matplotlib - matplotlib 中的相对图形大小