Simulink logging intervals with discrete and continuous blocks

4 次查看(过去 30 天)
Hi all,
In my Simulink Model are some Discrete Blocks (implemented as Level-2 Matlab S-Function) with period time T and also some continuous blocks.
Is it possible to log the output only when the discrete blocks change their output?
Thanks in advance, I really appreciate your answer.
  1 个评论
Paul
Paul 2024-7-7
By "change their output" do you mean a) when the value of the ouput changes, or do you mean b) when the block is updated at every T seconds, regardless of the value of the output?
It sounds like the model has multiple,discrete-time blocks. If the answer is (a), does the ouput of a specific block have to change, or a specific subset of them, or any of them, or all of them?
Do you want to log the ouput of the continuous time blocks as well only at the time determined by (a) or (b) above?

请先登录,再进行评论。

回答(1 个)

Umar
Umar 2024-7-7

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 个评论
ludolfusexe
ludolfusexe 2024-7-9
Hi, thank you very much for your answer! I had hoped for a quicker way but then I will implement it as you suggested. Once I've done that, I'll mark your answer as the solution.
Umar
Umar 2024-7-9
Hi ludolfusexe,
I appreciate your understanding and willingness to implement the solution as suggested. If you have any further questions or need assistance during the implementation process, please do not hesitate to reach out. Good luck!

请先登录,再进行评论。

类别

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

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by