Simulink logging intervals with discrete and continuous blocks
1 个评论
回答(1 个)
Hi ludolfusexe ,
It appears you are seeking a way to log the output of discrete blocks in your Simulink model only when their output changes. This can be achieved by implementing a conditional logging mechanism that triggers based on the change in output values from the discrete blocks.
To achieve this, you can utilize a combination of Simulink signal logging features and MATLAB scripting. One approach is to compare the current output of the discrete blocks with the previous output and log the data only when a change is detected. This can be done using MATLAB S-Function blocks or custom MATLAB scripts within your Simulink model.
Here is a high-level overview of how you can implement this:
1. Create a MATLAB script or S-Function block that stores the previous output values of the discrete blocks.
2. In your script or S-Function, compare the current output values with the stored previous values.
3. If a change is detected, log the output data.
4. Use Simulink's logging capabilities to record the desired output data.
Let me provide a simple example in pseudo-code to illustrate this concept in matlab:
% Initialize previous output values
prev_output = initial_value;
% Main simulation loop while simulation_running %
Get current output value from discrete block
current_output = get_discrete_block_output();
% Compare with previous output
if current_output != prev_output
% Log the output data log_data(current_output);
% Update previous output value
prev_output = current_output; end
% Continue simulation
end
By implementing this logic in your Simulink model, you can selectively log the output of discrete blocks only when there is a change in their values. This approach allows you to efficiently capture and analyze relevant data while minimizing unnecessary logging.
Let me know if I can provide further assistance.
2 个评论
另请参阅
类别
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!