Saving Scope Data in Simulink

16 次查看(过去 30 天)
Sugar Mummy
Sugar Mummy 2022-1-3
回答: Shlok 2024-8-21,11:23
Hello everyone,
I am working on a project where I have to save data of scope. I am using the code shown below but its not working for me as I want to save the data after every iteration and the scope have multiple variables attached. How can I do that?
for i =1:numel(All_IR)
IR=All_IR(i)
simOut=sim('ModelName')
Loggings(i).scopeData=scopeData
end

回答(1 个)

Shlok
Shlok 2024-8-21,11:23
Hi,
I understand that you want to save the scope data using the above given code. However, you need to address the following things to achieve the same:
1) Check if you have enabled Scope logging.
  • Open the Scope block in your Simulink model.
  • In the toolbar, go to View > Configuration Properties > Logging.
  • Ensure the "Log data to workspace" option is checked.
  • Assign a variable name, such as “ScopeData”, and select your preferred save format (e.g., "Array") from the dropdown menu.
  • Save the changes by clicking "OK".
2) Ensure the “SaveOutput” parameter in the “sim” function is set to "on". By default, it is "on," but if it has been disabled, you should explicitly set it as shown below:
sim('ModelName', 'SaveOutput', 'on');
3) In your code, you’re trying to access “scopeData” directly. Instead, you should extract it from the output of the “sim” function (eg: “simOut”, here), as it is stored there as a field.
Here is the modified code:
for i = 1:numel(All_IR)
IR = All_IR(i);
simOut = sim('ModelName', 'SaveOutput', 'on');
% Assuming the scope data is logged in "ScopeData" variable set using Configuration Properties panel
Loggings(i).scopeData = simOut.ScopeData;
end
For more information related to logging, you can check out the following documentation link:
Hope it helps.

类别

Help CenterFile Exchange 中查找有关 Save Run-Time Data from Simulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by