필터 지우기
필터 지우기

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

조회 수: 21 (최근 30일)
James
James 2024년 5월 9일
답변: Akshat Dalal 2024년 6월 28일 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.

답변 (1개)

Akshat Dalal
Akshat Dalal 2024년 6월 28일 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

카테고리

Help CenterFile Exchange에서 Large-Scale Modeling에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by