使用 Dymola 将特定变量写入 .txt 或 .mat [英] Writing specific variable to .txt or .mat with Dymola

查看:41
本文介绍了使用 Dymola 将特定变量写入 .txt 或 .mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法将模拟中的特定变量写入 .txt 或 .mat.

I am in need of a way to write a specific variable from a simulation to either .txt or .mat.

使用:

Streams.print(Modelica.Math.Vector.toString(resultVector),"filename"); 

与模拟选项卡上的变量导出相比,会导致错误的数据,因为没有一致性..txt 文件中的值完全不同,没有模式可见.

results in wrong data as in no acordance when compared to the export of the variable over the simulation tab. The values in the .txt file are completly different with no pattern visible.

推荐答案

Modelica.Utilities.Streams.writeRealMatrix 会满足您的需求吗?

对我来说

Modelica.Utilities.Streams.writeRealMatrix(
  fileName="C:/temp/test.mat", 
  matrixName="testMatrix", 
  matrix=[1,2;4,5], 
  append=false, 
  format="7")

产生了预期的 .mat 文件.

resulted in the expected .mat file.

为了能够在 .mat 文件中写入变量,您必须将变量转换为(二维)矩阵 - 如果它还不是一个.这可以通过使用方括号转换标量或向量来实现.这将为标量提供 matrix=[1] 或为向量提供 matrix=[{1,2,3,4}] .使用 matrix=1matrix={1,2,3,4} 会引发错误.

For being able to write a variable in the .mat file, you will have to convert your variable to a (two-dimensional) matrix - if it isn't already one. This can be accomplished by converting a scalar or vector using square brackets. This would give matrix=[1] for a scalar or matrix=[{1,2,3,4}] for a vector. Using matrix=1 or matrix={1,2,3,4} will trow an error.

这篇关于使用 Dymola 将特定变量写入 .txt 或 .mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆