Clear Filters
Clear Filters

Saving Scope Data in Simulink

16 views (last 30 days)
Sugar Mummy
Sugar Mummy on 3 Jan 2022
Answered: Shlok on 21 Aug 2024 at 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

Answers (1)

Shlok
Shlok on 21 Aug 2024 at 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.

Categories

Find more on Save Run-Time Data from Simulation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!