The purpose here is to:
- output some specific variables in a MAT file (without the complex structure offered by the standard Modelica output);
- without any post-processing i.e. after the simulation I'd like to have the MAT file ready-to-go, with no further steps (contrary to Writing specific variable to .txt or .mat with Dymola);
- not IDE specific (not using Dymola or OpenModelica specific commands);
- potentially without generating events;
The Modelica.Utilities.Streams.writeRealMatrix utility is what came to my mind at first, but I cannot make the append argument to work properly.
Here is what I tried:
model WriteRealMatrixToFileTest
discrete Boolean success;
discrete Real time_pre(start=0, fixed=true);
equation
when sample(0,0.1) then
success = Modelica.Utilities.Streams.writeRealMatrix("OutMat.mat", "OutMat", {{time, sin(time)}}, append=true, format="4");
Modelica.Utilities.Streams.print("Printing status at time " + String(time) + ": " + String(success));
time_pre = time;
end when;
end WriteRealMatrixToFileTest;
but, even though it always return succesfull and even if the command is correctly called at every 0.1s, in the MAT file I just find the very last value (e.g. {10, -0.544} if stopTime=10).
One option would be to reading back the MAT file, append the new set of values to the matrix, re-write them back again, but it sounds really ugly to me. Are there other ways? Since I cannot declare a dynamic-size matrix I cannot think of other options.