- 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 次查看(过去 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!
0 个评论
回答(1 个)
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:
% 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!