- 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!