## Working with time-series data in a Matlab Function in Simulink

Hi,

I’ve collected several data from 2 sensors outside Matlab enrivonment, i’ve loaded them in a Matlab file through a load operation once they were stored in a .mat file. Let’s call these two arrays "a" and "b". The sensors collected 18000 data each, working 30 mins, this means they have collected 10 values per second. I have converted the arrays in time-series using those lines:

Ts=0.1; %sampling time

timevals=[0:Ts:1799];

a_=timeseries(a,timevals);

b_=timeseries(b,timevals);

Then, i’ve uploaded them in Simulink through two "from workspace" blocks, i’ve computed their difference, let’s call it "error" and then i have to work with a dynamic PI controller, this means that after the sum block that i used to compute the difference, there are two branches where this difference, the error, enters. I just have to implement a very simple function (my idea is to use two different Matlab Function Blocks, one for each branch), if the error is bigger than a quantity, the proportional action will lead to y=error*Kp, if the error is smaller or equal than this quantity, the action is y=error*Kp/100. Same for integral action. This sees to be an easy task but once i try, i get so many errors that i don’t know from which one i should begin… the question is: how to deal with time series inside a Matlab Function block? I’m thinking there is a conceptual error i perform, so i’m looking for some advice. This would be very appreciated, thanks!!

Some of the errors I get:

1) Errors occurred during parsing of MATLAB function ‘MATLAB Function1’

2) Undefined function or variable ‘Kp’ -> i’ve definied it both in worspace and in matlab function but i continue getting this error…

3) Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.

4) Undefined function or variable ‘y’. The first assignment to a local variable determines its class.

PS. I’ve also computed the two results easily in Matlab, getting the two arrays y and y1 (for proportional part and integral part). Could it be good to convert them in time-series and plug them in the Simulink model? In this way i will avoid performing the function in Simulink, but in this case i only find input time-series block, so i don’t know how to put them in the middle of a simulink model. Simulink is really needed so I can’t avoid it and just writing a Matlab script because the future operations are related to integrators and rate limiters that would be very complex without Simulink…Hi,

I’ve collected several data from 2 sensors outside Matlab enrivonment, i’ve loaded them in a Matlab file through a load operation once they were stored in a .mat file. Let’s call these two arrays "a" and "b". The sensors collected 18000 data each, working 30 mins, this means they have collected 10 values per second. I have converted the arrays in time-series using those lines:

Ts=0.1; %sampling time

timevals=[0:Ts:1799];

a_=timeseries(a,timevals);

b_=timeseries(b,timevals);

Then, i’ve uploaded them in Simulink through two "from workspace" blocks, i’ve computed their difference, let’s call it "error" and then i have to work with a dynamic PI controller, this means that after the sum block that i used to compute the difference, there are two branches where this difference, the error, enters. I just have to implement a very simple function (my idea is to use two different Matlab Function Blocks, one for each branch), if the error is bigger than a quantity, the proportional action will lead to y=error*Kp, if the error is smaller or equal than this quantity, the action is y=error*Kp/100. Same for integral action. This sees to be an easy task but once i try, i get so many errors that i don’t know from which one i should begin… the question is: how to deal with time series inside a Matlab Function block? I’m thinking there is a conceptual error i perform, so i’m looking for some advice. This would be very appreciated, thanks!!

Some of the errors I get:

1) Errors occurred during parsing of MATLAB function ‘MATLAB Function1’

2) Undefined function or variable ‘Kp’ -> i’ve definied it both in worspace and in matlab function but i continue getting this error…

3) Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.

4) Undefined function or variable ‘y’. The first assignment to a local variable determines its class.

PS. I’ve also computed the two results easily in Matlab, getting the two arrays y and y1 (for proportional part and integral part). Could it be good to convert them in time-series and plug them in the Simulink model? In this way i will avoid performing the function in Simulink, but in this case i only find input time-series block, so i don’t know how to put them in the middle of a simulink model. Simulink is really needed so I can’t avoid it and just writing a Matlab script because the future operations are related to integrators and rate limiters that would be very complex without Simulink… Hi,

I’ve collected several data from 2 sensors outside Matlab enrivonment, i’ve loaded them in a Matlab file through a load operation once they were stored in a .mat file. Let’s call these two arrays "a" and "b". The sensors collected 18000 data each, working 30 mins, this means they have collected 10 values per second. I have converted the arrays in time-series using those lines:

Ts=0.1; %sampling time

timevals=[0:Ts:1799];

a_=timeseries(a,timevals);

b_=timeseries(b,timevals);

Then, i’ve uploaded them in Simulink through two "from workspace" blocks, i’ve computed their difference, let’s call it "error" and then i have to work with a dynamic PI controller, this means that after the sum block that i used to compute the difference, there are two branches where this difference, the error, enters. I just have to implement a very simple function (my idea is to use two different Matlab Function Blocks, one for each branch), if the error is bigger than a quantity, the proportional action will lead to y=error*Kp, if the error is smaller or equal than this quantity, the action is y=error*Kp/100. Same for integral action. This sees to be an easy task but once i try, i get so many errors that i don’t know from which one i should begin… the question is: how to deal with time series inside a Matlab Function block? I’m thinking there is a conceptual error i perform, so i’m looking for some advice. This would be very appreciated, thanks!!

Some of the errors I get:

1) Errors occurred during parsing of MATLAB function ‘MATLAB Function1’

2) Undefined function or variable ‘Kp’ -> i’ve definied it both in worspace and in matlab function but i continue getting this error…

3) Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.

4) Undefined function or variable ‘y’. The first assignment to a local variable determines its class.

PS. I’ve also computed the two results easily in Matlab, getting the two arrays y and y1 (for proportional part and integral part). Could it be good to convert them in time-series and plug them in the Simulink model? In this way i will avoid performing the function in Simulink, but in this case i only find input time-series block, so i don’t know how to put them in the middle of a simulink model. Simulink is really needed so I can’t avoid it and just writing a Matlab script because the future operations are related to integrators and rate limiters that would be very complex without Simulink… time series, matlab function, simulink MATLAB Answers — New Questions