Demux vector from workspace - matlab

I have vector defined in workspace. I would like to get every element in vector to different inputs in my simulink model. I can't demux vector. Does anyone know how to do it?

Related

Simulink: Vector summation and saving the output to workspace

I can not solve a very simple problem in the Simulink: summation of 2 equal size vectors and writing the result into the Matlab workspace.
The trivial operation that takes 1 line in Matlab seems a real problem in the simulink.
I have 2 vectors with the same size, for e.g. 10x1 and I want to get their summation result into the workspace with the same size (10x1).
I have already used 'sum' block for that and even my own function with element-wise summation, but I think the problem is that Simulink block 'to workspace' always concatenate outputs either along 1-st or 3-rd dimension. Hence the size of the output does not inherit the size of inputs.
I can not find any solution in the web, will be really appreciate for your help!
I didn't notice the vectors are saved in a column-based using "to workspace" block. Did you try to add "(:)" in your code to get it in a single column?
As I know, storing the data in columns (1x10) is faster than in rows (10x1). Maybe that is the reason for getting columns instead of rows.
https://www.mathworks.com/matlabcentral/answers/216512-which-is-faster-a-row-vector-or-a-column-vector-can-anyone-answer-me-please

How to get a vector or matrix output to workspace using simulink?

This is a fairly simple thing I think, but I cannot seem to get the right output that Im looking for. I am using matrices to represent state space models in simulink, and I am trying to get my states output to the workspace,
it is a simple 4x1 vector, and I tried just using the regular "to workspace" block, but it seems it concats to either a 2d or 3d vector..
I want to have a tx4 matrix output that I can reference the first state and plot for all simulation time(t) like x(:,1), the second state x(:,2) etc...
You can set a save format in a To Workspace block. Default this is set to timeseries, but you can set it to Array.
Looking at the doc for the Array setting:
If the input signal is a scalar or a vector, each input sample is output as a row of the array. Suppose that the name of the output array is simout. Then, simout(1,:) corresponds to the first sample, simout(2,:) corresponds to the second sample, and so on.
You want the first dimension not to be time, but your state vector, so transposing simout should do the trick.
simout = simout.'; % or tranpose(simout);

How can one input an arbitrary array to Simulink?

The image below is the quadrotor model in simulink, now it's following a path made of sine waves for x and y.
If I want the quadrotor to follow a path made of predefined x,y,z values, how can I specify that?
The most logical way to do this is to create an arbitrary timeseries variable in MATLAB and then use it as an input in Simulink using a "Read data from workspace" block

Simulink transfer fcn with matrix as parameters

Let's say I want to model this equation (electrical motor, 6 phases):
Vs = Rs*Is + d/dt*(Ls*Is)
where all variables are matrix, so:
Vs = [va1 vb1 vc1 va2 vb2 vc2]' (column vector)
Is = [ia1 ib1 ic1 ia2 ib2 ic2]' (column vector)
Ls and Rs are 6x6 matrix (constants)
From my point of view the Vs is the input vector and Is is the output vector so I need to rearrange the equation.
I have seen that is not possible in Simulink to feed the Transfer Fcn block with matrix, at least not for a multiple input multiple output system.
Is there a way to realize this on Simulink still using the matrix Ls and Rs without "unpacking" the equation?
Thank you
I would re-arrange your equations in state-space form and use the State-Space block, which is better suited for matrix equations.
Another option is to use basic Simulink blocks, such as Integrator and Gain blocks, with vectorized inputs. I am not 100% sure this will work, but reasonably confident.
You can use the product block with matrices inside Matlab so there should be no problem. It's also possible to use integrator/derivative block (though it's better to avoid using derivative if possible) with a vector input so if you can put your equation with Is as an output there should be no problem.
You can put 2 multiply blocks with your matrices as inputs and the vector you need and you will get a vector for the output like you want.

State-space in simulink with one scalar input

I am using state-space block along with a mux in simulink. I am having two inputs so after passing through mux block I get a row vector. As state-space block accepts one scalar input so when a row vector is given as an input it doesn't work. Any help would be greatly appreciated.
First you should check the dimensions of your state space matrices A,B,C & D. If matrix B is of nx2 then one can use a mux; where n is the order of the system.