英文:
Which are the steps to import a text file and an Excel file on Modelica?
问题
I want to use data for my model from two files: one with extension .txt and the other one with extension .csv. Then I want to have access to that specific data to process it as parameters. Do I have to use a function? What would be your take on this topic? Thank you!
PD: I'm using OpenModelica.
I've tried the ExternData library, but I think I don't get it quite right.
fileName = Modelica.Utilities.Files.loadResource("modelica:/Files/Examples/CSVReader/Data.csv")
英文:
I'm having a little trouble here. I want to use data for my model from two files: one with extension .txt and other one with extension .csv. Then I want to have access to that especific data to process it as parameters. Do I have to use a function? What would be your take on this topic? Thank you!
PD: I'm using OpenModelica.
I've tried the ExternData library but I think I don´t get it quite right.
fileName=Modelica.Utilities.Files.loadResource("modelica:/Files/Examples/CSVReader/Data.csv"),
答案1
得分: 3
我认为ExternData
库是一个相当不错的选择。它支持多种文件类型,应该能满足您的需求,尽管问题在这方面有点模糊。
您有没有看过ExternData.Examples.CSVTest
?那应该解释了该库的使用方式。基本上,它是一个两步过程:
- 您使用
dataSource
类来指定文件的路径以及文件类型。 - 然后通过
dataSource
中相应的函数来访问数据,例如dataSource.getRealArray2D(3, 2)
,其中的整数定义了要读取的矩阵的大小。
更多详情请参阅:https://ecp.ep.liu.se/index.php/modelica/article/view/189。
英文:
I think the ExternData
library is a pretty good choice. It supports both file-types and should do what you want - although the question is a bit fuzzy in that regard.
Did you take a look at ExternData.Examples.CSVTest
? That should explain how the library is used. Basically, it is a two-step process:
- You use the
dataSource
class to specify the path to the file as well as the file-type. - Then you access the data via the respective functions (re)-declared in the
dataSource
, e.g.dataSource.getRealArray2D(3, 2)
with the integers defining the size of the matrix that is read.
For more details: https://ecp.ep.liu.se/index.php/modelica/article/view/189.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论