How can one input an arbitrary array to Simulink? - matlab

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

Related

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);

Simulink: Spline interpolation on Inports?

I have a Simulink simulation that takes a control input U on an Inport, and simulates the state of the system based on that input. I want the simulation to use a variable time-step ode solver, but U is going to be defined as discrete time points (that aren't evenly spaced) that certainly aren't going to align with the times that are generated by (say) ode15s.
I want Simulink to take the U vector and a time vector, and use cubic spline interpolation to determine the value of U for times that do not align with the given U vector--similar to the 'Interpolate Data' option in the Inport preferences, except again my data is neither evenly spaced, nor do I want linear interpolation. How can I do this?
A possible way to achieve this is the following. I am assuming the U vector is already known beforehand. This is implied from the fact the vector values are given at random sample moments which are not matching with the solver sample moments.
Take an '1-D interpolation table' block and connect a 'Clock' block as input. In the 1-D interpolation table you are able to specify 'Table data' in your case the values of the U vector. And you are able to specify the breakpoints that are in your case the time points. These can be variables from your workspace.
Then under the tabled 'Algorithm' you choose 'Cubic spline' for the interpolation method.
That should do the trick.

Simulink block for plotting output (on Y axis) with input (on X-axis)?

Time dependent signal is input to a Simulink model which give time dependent output, both are continuous functions, we can separately plot input/output signal values as a function of time but we want to plot input value with output value for a particular time. Does Simscape have block for that? please help. Thank you in advance.
The xygraph block allows you to input a signal for both, the x and the y axis.

How to make a continuous time signal in MATLAB to use in Simulink?

I want a trajectory to be created in MATLAB, but I am unable to find how can I make this function continuous.The function is
fsg=abs((sign(t-a)-sign(t-b))/2), and the trajectories are x=t.*fsg(t,0,20)+20.*fsg(t,20,40)+(60-t).*fsg(t,40,60)
, y=(t-20).*fsg(t,20,40)+ 20.*fsg(t,40,60)
and
z=0
How can I create it, because my model is continuous and I want to give continuous input to it. What i had done is: I created fsg function in MATLAB and created time t=[0:.1:80]. Then, I calculated x,y,z and then created a timeseries variant of these to give them as input to my model.

Matlab Simulink graph plotting

I plotted a signal using "To Workspace" in Simulink Matlab. Now I want to take the mean of the specific part of that signal which I plotted.How can I extract values from "To Workspace" or how can I take the mean of the specific area of that graph.
In "To workspace" you define a variable name, let's say: "simout"
I made a simple simulink as the following:
you can save with different formats: Timeseries, Structure with time, Structure, Array.
Then, when you run the simulink, it will save the variable in the worksapce as a structure.
Then you can use the variable to plot the data inside. check this example :
consider you saved using Structure with time you can get data like this:
t = simout.time
x = simout.signals.values
and you can plot the data:
plot(t,x)