Update indices in Simulink

12 次查看(过去 30 天)
Fabrizio Leoni
Fabrizio Leoni 2023-3-27
Hello!
I'm creating a thermal model for a tyre on Simulink. The model has as inputs data from track testing (for instance, the force that the tyre generates).
It uses these inputs and the temperature of the surface of the tyre to calculate the heat generated by friction, Q. From Q, it then calculates T_dot, the rate of change of the temperature of the tyre surface. From T_dot, by integration, the surface temperature T can be obtained.
The temperature calculated at instant 1 is then the input for instant 2.
What I would like to do now is to update all the array elements at every iteration. That is, I want my model to take the first element of the force array at the first instant and the initial value for the temperature. Then at the second instant, the model should take the newly calculated temperature and the second element of the force array, instead of the whole vector every time.
Ideally, I would like to write F(i) as an input (i.e., the i-th element of the array F), and then update the index i as it proceeds with the iterations. That's quite easy to do in Matlab, but I need this to be in Simulink.
I have tried to combine the Counter block (to "create" the index i). Then I input the output of the counter block and the force array into the "Vector Index" block. I expected the counter block to work like a constant that updates at every iteration (it's 1 at the first instant, then 2, 3 etc). From the force array, I want to extract the element that has the index equal to the value of the counter, by using the Vector Index block.
This isn't working though:
An error occurred while running the simulation and the simulation was terminated
Caused by:
The vector index block requires to specify the indices. I'm wondering if there is a way to input these indices as a variable.
More in general, I'm wondering if there is another way (possibly faser and more intelligent) to update my array indices.
I have also tried to write a matlab function that simply does i = i+1, and put it right after the integration block (so that every time that I pass by the integration block, it updates i), but that's not working either (i should be the input to the matlab function, but I also need this function block to be in the iterative loop otherwise it won't change).
I hope I've been clear.
Thank you so much for your help,
Fabrizio

回答(1 个)

Maneet Kaur Bagga
Maneet Kaur Bagga 2023-8-29
As per my understanding of the question, the problem contains a Force Array and the initial temperature is defined which is used with the first element of the Force array to calculate the heat generated by the friction Q, which in turn generated a surface temperature which is used subsequently in the next round of iteration.
The For Iterator Subsystem block can be used as iterator to iterate over the Force Array using the index vector block and the iterated assignment with the Assignment block can be used to fetch the temperature for each successive steps of iteration assuming that the initial temperature is given as T0 for the first iteration. Temperature and Force are then passed as inputs to the MATLAB Function Block to define the algorithm for the heat generated due to friction Q and hence the output temperature for the next iteration.
You can refer to the model attached below for the idea on how to implement the model.
You may also refer to the question attached below for the implementation of for loop subsystem in Simulink:
You can also refer to the articles below:
Implementation of For loop Subusytem Block:
Iterated Assignment using Assignment Block to update the value of temperature after each iteration:
How to fetch the array elements using For Loop Subsytem Iterator and Constant block containing vector of Force Values using zero and one based indexing:

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by