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

回答(1 个)

Shishir Reddy
Shishir Reddy 2024-8-27
编辑:Shishir Reddy 2024-8-27
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:
  • 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.
% 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.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by