Why does matlab rename my simulink logsout file?

Hello,
I would like to run multiple simulation with batchsim. The following code should setup the required simulation input objects in a for loop.
The newFileName variable stores the required logsout.mat file names. Example: {'simulationfile_a.mat', 'simulationfile_b.mat', 'simulationfile_c.mat'}
After running the simulation with batchsim I got logsout.mat files with name like 'simulationfile_a_1.mat', 'simulationfile_b_2.mat', 'simulationfile_c_3.mat'.
Why?
How to rename the files to the original?
This this renaming only happens with batchsim. With parsim it was ok.
%Setup SI
in(i) = Simulink.SimulationInput(model);
in(i) = in(i).setModelParameter(...
'StopTime', num2str(stop_time.sim_end),...
'LoggingFileName', newFileName{i},...
'SignalLogging', 'on',...
'LoggingToFile', 'on',...
'SaveFormat', 'Dataset',...
'SaveTime', 'off',...
'SaveState', 'off',...
'SaveOutput', 'off',...
'SaveFinalState', 'off',..
'DSMLogging', 'off',...
'ReturnWorkspaceOutputs', 'on',...
'Profile', 'off',...
'InspectSignalLogs', 'off',...
'DatasetSignalFormat', 'timeseries');
%run batch
simJob = batchsim(myCluster, in, ...
'Pool', min(myCluster.NumWorkers-1, length(newFileName)),...
'AutoAddClientPath', false,...
'ManageDependencies', 'off',...
'AttachedFiles',filesToAttach,...
'ShowProgress','on',...
'TransferBaseWorkspaceVariables', 'off',...
'CleanupFcn', @Simulink.sdi.clear);

Respuestas (1)

Hi Szabo,
As per my understanding of the question, the batchsim performs a different naming convention because it distributes the simulation tasks across multiple workers in a cluster, allowing for parallel execution of the simulations. Each worker performs a separate simulation and generates its own output file where as parsim executes the simulations sequentially, one after the other without distributing them to multiple workers. So the output files enerated by different workers are appended with a number to avoid conflicts.
To rename the files generated by batchsim back to their original names please follow the steps below:
  • Use the "wait" function to wait for all the jobs to finish.
  • Once the jobs are finished, iterate over the new file names and rename them back to their original names using the "movefile" function
wait(simJob);
for i = 1:length(newFileName)
oldFileName = sprintf('%s_%d.mat', newFileName{i}, i);
movefile(oldFileName, newFileName{i});
end
% newFileName refers to the array of original file names
% i represents the index of each simulation run.
Please refer to the following MATLAB Documentation for better understanding:
Comparison Between Multiple Simulation Workflows
movefile
wait
I hope this helps!
Thank You
Maneet Bagga

5 comentarios

Thanks for the answer, but I don't want to halt my matlab session. The batchsim often runs for hours.
Why the parsim runs sequentially compared to batchsim? I can see in my workstation that it also runs simulations in parallel. For sure it uses fewer workers but still in parallel. Why the batchsim is differs from the parsim?
Thanks,
Bence
Paul
Paul el 11 de Sept. de 2023
Does batchsim really differe from parsim? This answer shows that parsim also automatically adds _1, _2, etc. to the LoggingFileName.
For the difference between the two function parsim and batchsim you may refer to the following documentation:
@Paul You are right. The batchsim and parsim is the same. Have just tested in 2020b and 2019a. I was wrong about that.

Iniciar sesión para comentar.

Categorías

Más información sobre Run Multiple Simulations en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Preguntada:

el 18 de Ag. de 2022

Comentada:

el 30 de Oct. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by