# Dimensions of arrays being concatenated are not consistent error .

4 views (last 30 days)
Stilian Iliev on 10 Jan 2022
Commented: Stilian Iliev on 12 Jan 2022
Hello. I have to simulate a system of 2 differential equations using the State Space block. Problem is that one of the variables, a mass m, has to come after 0,2s from start of simulation. I've tried using a Step with "To Workspace" block but it outputs the variable as a timeseries and gives an error. So I switched it to an If case with a clock and the error is different now :D - namely:
Simulation (Elapsed: 0.506 sec) ===
Error:Invalid setting in 'LB3/State-Space' for parameter 'A'.
Caused by:
Error evaluating parameter 'A' in 'LB3/State-Space'
Dimensions of arrays being concatenated are not consistent..
Here's a photo to better understand what's going on.Also in the subsystem is just a PID controller with a saturation block - nothing special. And simulation is 1 second long.
Any help is much appreciated.
Stilian Iliev on 12 Jan 2022
Yea, it's just coincidence that both the mass and switch time are 0,2.

Jon on 12 Jan 2022
There is a problem with your approach, which is setting the initial condition for the second block (the one that the switch is connected to after 0.2). Since physically the system states can not change instantaneously, the system state of the second block should match that of the first when the switch occurs. Unfortunately although the two systems will be driven by the same input, their states will not be the same because they have different parameters (the mass is different). So the states of the two blocks will not match at the time the switch occurs. To overcome this you would need a way to set the initial condition for the second block at the time of the switch. Unfortunately the Simulink state space block does not have any external input for setting the initial condition. The initial condition is a parameter, which stays constant throughout the simulation. So I don't see how you will do this.
Another approach, instead of using a switch would be to use two enabled subsystems, each with a state space block inside of them. The outputs of the two would be input to a merge block. Unfortunately I think you will have the same problem with initial conditions. There are some possibilities of resetting states, and hold outputs, that might hold some possibilities, but I don't immediately see a solution even using these.
There is one easy solution though if you have the Contol System Toolbox. The Varying State Space Model, which is in the Control System Toolbox, https://www.mathworks.com/help/control/ref/varyingstatespace.html would work perfectly for your application. You just feed it the time varying A,B,C,D and could provide any necessary switches (or maybe even just steps on those signals)

R2021a

### Community Treasure Hunt

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

Start Hunting!