How to save calculated value into Simulink workspace

Hello,
I have got a question about the State-Space block. I would like to use one of the output values as a coefficient for matrix A .
That means following - I want to calculate y ; demux the output signal; grab the last calculated value and save it into the Simulink workspace as a constant btS (eventually overwrite the initial value which was set in Model properties->Callbacks->InitFcn); use it in the other calculation step.
Unfortunately the To Workspace block doesnt work because it writes the value after the calculation stopped. Is there any way how to do that?
Principle is shown on following figure.
Thank you

 Accepted Answer

The easiest thing to do when your system is nonlinear (as in your case) is not to use a State-Space block. Instead, if possible, try decompose your system into foundational blocks like Integrator, Add/Subtract, Gain, etc. blocks.
This way, you can easily feed that output signal back into a Product block without having to do any "hacking" with the workspace.
In fact, you could just take those matrices and implement the state-space math using matrix operations and one Integrator block. That is, xdot = A*x + B*u and y = C*x + D*u. Then, you could use an Assignment block to keep tuning a particular element of A using that one output element.
- Sebastian

3 Comments

Hello,
If I understand you - you mean decompose State-space block into this:
Unfortunately I am not so experienced in Simulink and I am not sure if I can do this.
First of all - how to create a matrix with dimension for example 6x6. I have seen there is a matrix block with size 3x3 in the Simulink library. Can I simply create the 6x6 matrix or bigger?
Another problem is multiplication of matrices and vectors. For example there is a vector u which multiplies the matrix B . Is there any tool/block which allows this? And can I somehow force them to multiply B . u not u . B ?
Thank you
Yes! All of these multiplications can be done by plain Simulink blocks.
If your matrix is constant (as will be the case for your B, C, D matrices), you can use a Gain block and set its Multiplication parameter accordingly.
If your matrix is not constant (as is the case with your A matrix), you can use a Product block, which also has a Multiplication parameter that you can set for matrix multiplication.
Similarly, the Integrator block handles vector/matrix signals automatically.
Now, as far as how to create matrices, I'd refer to this link:
- Sebastian
It works well. Thank you.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 9 Jul 2015

Commented:

on 16 Jul 2015

Community Treasure Hunt

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

Start Hunting!