Borrar filtros
Borrar filtros

How can I swap states in a simulink "for each" system?

5 visualizaciones (últimos 30 días)
James
James el 9 de Mayo de 2024
Respondida: Akshat Dalal el 28 de Jun. de 2024
I am trying to simulate multiple state-space models running in parrallel using a "for each" subsystem. At a given time or when a condition is met, I would like to "swap" the states during this simulation, e.g. reset the integrators so that the states from system 1 are assigned as the initial conditions for system 2 and the states of system 2 are assigned as the initial conditions to system 1. I can get this to happen if I trigger the reset based on time, i.e. with a step function. However, if I try to trigger the reset based on the states themselves there is a gap and the destination states get set to where the origin states were one timestep ago. Is there a way that I can fix this? See attachment.

Respuestas (1)

Akshat Dalal
Akshat Dalal el 28 de Jun. de 2024
Hi James,
The issue you're facing is likely due to the fact that the state update in your simulation happens in discrete time steps, and the reset condition based on the states themselves introduces a delay.
You could try using Stateflow for implenting the swapping infrastructure. This allows for more complex logic and can help ensure that states are swapped simultaneously without delay.
You can also use a triggered subsystem that activates based on the required condition and swaps the states using a logic defined in a MATLAB Function block.
The logic in the MATLAB Function block could be implemented as follows:
function [state1, state2] = swapStates(state1, state2, condition)
% Swap states if condition is met
if condition
temp = state1;
state1 = state2;
state2 = temp;
end
end

Categorías

Más información sobre Large-Scale Modeling en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by