Azzera filtri
Azzera filtri

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

21 visualizzazioni (ultimi 30 giorni)
James
James il 9 Mag 2024
Risposto: Akshat Dalal il 28 Giu 2024 alle 9:34
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.

Risposte (1)

Akshat Dalal
Akshat Dalal il 28 Giu 2024 alle 9:34
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

Categorie

Scopri di più su Large-Scale Modeling in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by