Saving Timeseries out of Workspace as Matlab file

52 Ansichten (letzte 30 Tage)
Sascha Liese
Sascha Liese am 22 Jun. 2022
Bearbeitet: Ishaan Mehta am 25 Jun. 2022
So I have a Simulink Modell which I let run automatically via Matlab Skript. I will load in the Modell different Kp and Ki Values for the PI-Controller. Then I have to look if the System is stabil. This is already working and I also get via eigen-values a clue if it is stabil. I have to save them which I do by ploting them.
But I also have to save some timeseries data which I already get from Simulink into my Matlab Workspace via the [TO Workspace Block]. I cant make leftclick and save as because I doing all this in a loop. So I need a code which allows me to save the Timeseries Data as a Matlab file automatically. Best even a counting one, so I dont overright my older saves just because the all have the same name. I hope someone can help me. I already tried
saveas(timeseriesname,[path.mat]);
I found this Code in the Internet where someone also saved timeseries with it (at least what he said). But for me its not working because of the Error: "Invalid handle".
P.s.: Sorry for my bad english :)

Antworten (1)

Ishaan Mehta
Ishaan Mehta am 25 Jun. 2022
Bearbeitet: Ishaan Mehta am 25 Jun. 2022
Hi Sascha
As per my understanding, you want to save a variable (containing a timeseries) in a .mat file with a dynamic name.
This can be easily achieved using MATLAB's save function.
Please refer to the following article for more details about the save function: Save workspace variables to file.
You can use the following code as a starting point:
count = 1;
for i = 1:10
filename = "myTimeseriesFile" + string(count);
% get timeseries into the workspace from your simulink model
timeseriesVar = timeseries(1:10); % dummy timeseries for demo
save(filename, 'timeseriesVar');
count = count + 1;
end
Cheers
Ishaan Mehta

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by