How do you update row vector elements during a real-time simulation in Simulink?

3 views (last 30 days)
Hey Guys
Im really stuck and really need help. So any suggestions would be really appreciated!
Im running a real-time simulation in Simulink with a 6 DoF vehicle model (with inputs from a joystick). One of the inputs to the model is a row vector which needs to be updated depending on the vehicle position. I have made a matrix, of which the rows correspond to the different row vectors that are needed, depending on the position of the vehicle.
How can I switch between the rows of the matrix during a simulation, based on the current position of the vehicle (position is one of the output states of the model)?
I have made it possible for me to know with a an index variable, 'i', when I have to switch to the next row in the matrix. I did this with a 'Matlab Function' block that uses a series of nested 'if else' statements to return a value for i, which corresponds to the row that I need from the Matrix. I tried sending this variable to the work-space and then modify the row I need from the matrix, which is put in a 'constant' block with argument:
Matrix(i,:)
But unfortunately, I think Simulink initializes constants during the start of the simulation, and I don't think the values can then be updated later: It never switches from the first row to subsequent rows of the matrix, even though the value of 'i' is changing at the right times, and is being called from the work-space using the 'from work-space' block. Also for some reason, I couldn't do this so easily with a 'Matlab function' block as it claims the ':' is "unable to parse".
Please Help!!!
ESunil

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 6 Aug 2012
Edited: Azzi Abdelmalek on 6 Aug 2012
i think you can use a "multiport switch" block with n+1 iputs, n inputs for your rows and 1 for the control signal

More Answers (1)

Giorgio Concu
Giorgio Concu on 22 Nov 2017
Hi! I have the same problem, but I have to uptade a 125x1 vector so it is not smart to implement a multiport switch. Do you have any other suggestions? Thank you!

Products

Community Treasure Hunt

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

Start Hunting!