- Connect the ‘To Workspace’ block to the input port and run the simulation.
- Refer this documentation to understand how this block is connected and configured https://www.mathworks.com/help/simulink/slref/toworkspace.html
- The data will be stored in the MATLAB workspace under the specific variable name.
- Set the threshold value on Input port using the code below. Note that it is assumed that ‘To Workspace’ block is configured to save data in ‘array’ format.
Obtain the port value in real time, and judge the size of the value. If the value is not met, a warning is reported.
2 views (last 30 days)
Show older comments
I created a module myself that wanted to limit the value of the input port, which I hope to implement through code. How to obtain the module's input port signal value and real-time judgment, does not meet the requirements then report the high alarm!
0 Comments
Answers (1)
Shishir Reddy
on 27 Aug 2024
Edited: Shishir Reddy
on 27 Aug 2024
Hi Fangping
Visualizing the value of an input port in real time can be done in Simulink using the scope/ display blocks. Refer to the link below to understand the implementation.
To extract values from Simulink model and process them using MATLAB code, the ‘To Workspace’ block in Simulink can be leveraged. This exports data from simulation to MATLAB workspace. You can follow the below mentioned steps to achieve this in MATLAB:
% Assume inputData is the variable name used in the To Workspace block
% Extract the time and signal value
time = inputData(:, 1);
values = inputData(:, 2);
% Define the threshold
threshold = 50;
% Check for values exceeding the threshold
exceedingIndices = find(values > threshold);
% Report warnings
if ~isempty(exceedingIndices)
fprintf('Warning: The input value exceeded the threshold at the following times:\n');
disp(time(exceedingIndices));
else
disp('All input values are within the threshold.');
end
I hope this is useful.
0 Comments
See Also
Categories
Find more on Simulink Functions 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!