Saving Timeseries out of Workspace as Matlab file

49 次查看(过去 30 天)
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 :)

回答(1 个)

Ishaan Mehta
Ishaan Mehta 2022-6-25
编辑:Ishaan Mehta 2022-6-25
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

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by