Creating a powercurve in an function block from table of values - simulink

I would like to create a 'Matlap function' block in Simulink for simulating an wind power plant with real data. Input should be wind speed, output power.
So far I struggle creating the function from a value table trying to use "polyfit" and "polyval". Is there another possibility?

Why don't you use a 1-D Look-up table?

Related

Simulink MATLAB function block with vector inputs

I'm new to Simulink and am working on a project.
The bigger picture is that I want to gather different sensor data, pick out an interval of that, and in my Matlab functions analyze it, a kind of adaption. It feels like I have a fundamental misconception since I thought my Matlab scripts could work directly in Simulink. I have a couple of Matlab function blocks which in Matlab takes vectors as inputs, but when I use a source such as "from workspace" I get the error that it cannot handle more than one value at the same time: Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
So I wonder if there is any neat way of collecting a given interval of a continuous flow of sensor data (as a beginning, the raw input will just be a vector which will represent sensor data) so that it could be analyzed by some Matlab functions?

Sample sequence of points from continuous signal simulink

I have a Matlab function (created by me) that must be evaluated only at a given rate. I would like to sample the value of a signal, give to this function (discrete values) and then, the calculated output must be hold until the next value is available. Is there a way in simulink to do this? All answers I have found use quantizer + ZOH but in this case I still get "a continuum" (or almost it) of points to be evaluated by thsi function which is really slow. Changing the rate of simulink's solver is also not an option as the result of this function will be given for a continuous time system.
Any help will be highly appreciatted!
Thank you
Assuming by Matlab function you mean a MATLAB Function block, then it sounds as if all you need to do is make the block discrete. Do that by right-clicking on the block, going down to Block Properties and then in the resulting dialog enter your required sample time.
The block will then sample its input and generate an output (which is held between sample times) at each sample time.

How to iterate over values of models in Simulink Matlab?

I have designed a model in simulink. Generally, I generate a plot by setting the values of blocks(eg.gain) in the model and simulating the model and opening the scope block. But I need to generate different grpahs corresponding to different values of blocks(eg.gain). Basically, for different values of Gain value, I want different graphs but all in the same plot. The different values I give to my gain should be from an array. This is my model
I am using MATLAB for the first time. Please answer this in a beginner's approach
Setting The Gain Value
The values of the gain blocks can be can be set as variables rather than constants i.e. you can give a gain block the value of K in the settings panel.
You can then create a script that gives K a value e.g;
%script to set gain and run model
K=2;
sim('Model Name Here');
This will set the value for your gain block and run the model.
Saving The Output
In the sinks section of the simulink library browser is a block called To Workspace, this allows you to send any output value to the MATLAB workspace in multiple formats with a name that you define.
Your simulink model will now look something like this;
Now you can create a script that sets a gain value for your model, runs the model and saves the output to your workspace. With a couple of for loops and you can produce an array of inputs and outputs for your system.
From here you should be able to plot the inputs and outputs on the same graph using the well documented plot function.

Iterate over array from workspace at each sample time in Simulink MATLAB function block

I have a MATLAB function block embedded in a Simulink model. In my initFnc callback I set up some vectors which I need to use in my function block inside the simulink model. The vector is 1x10000 and contains setpoints for a robotic arm. The function block simply needs to read the next value at each sample iteration.
So far I've tried using "From Workspace" and "evalin()" but they all throw various errors when building the model (I'm using code generation which doesn't play nice all the time).
What would be a good way to read in that vector in Simulink and feed the cells one by one into my function block? Something like repeating sequence stair but without the repeating part.
I got it to work by reading in the vector into a constant block and feeding that into my embedded function. I then use a persistent iterator which is a 1x1 matrix (ones(1)) and incrementing it every time the value from the vector is read.

Simulink - Find computed index of multidimensional signal at specific time

I am trying to find which element(index) of a multidimensional signal is computed at a specific time in a Simulink model. Assume that there is a multidimensional input signal given to an add block together with a constant so Simulink calculates the sum with the constant for each element of the signal and gives the output as multidimensional signal. I want to know which index of the signal is computed at a time so I can do additional computation. How can I do that?
Do you want to do additional computation during simulation or after? In the latter case, you can save the multidimensional signal to the MATLAB Workspace as a "structure with time" variable. Then do your additional computations by finding the index of the time point of interest and the associated multidimensional data point. In the former case, you can probably a MATLAB function block with two inputs: the output of a clock block and the multidimensional signal. Then do your processing in there using MATLAB code.