Azzera filtri
Azzera filtri

How to output a timeseries from matlab function in simulink?

21 visualizzazioni (ultimi 30 giorni)
Hello, I am trying to output a timeseries from a matlab function in Simulink. I am calling a function inside the matlab function block that should output timeseries data. The problem is that although I converted the data into a timeseries inside the matlab function, whenever I run the model, I have an error which says that the output of function is not numeric. I initialized the output of the Matlab function block and used the "double" Function for it but with no success. I will appreciate any help.Thanks in advance.
  2 Commenti
Walter Roberson
Walter Roberson il 19 Apr 2023
It sounds like you have a setup similar to
function y = fcn(first_input, second_input)
y = zeros(some size); %pre-allocate
z = some_function_that_returns_timeseries;
y = z.Data; %extract the numeric data from the timeseries
end
??
Or do you have
function y = fcn(first_input, second_input)
y = zeros(some size); %pre-allocate
y = some_function_that_returns_timeseries;
end
?
Mohamed Abdullah
Mohamed Abdullah il 19 Apr 2023
Modificato: Mohamed Abdullah il 19 Apr 2023
Yes, I have the second setup type.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 19 Apr 2023
Using the code outline
function y = fcn(first_input, second_input)
y = zeros(some size); %pre-allocate
y = some_function_that_returns_timeseries;
end
The problem with this kind of setup is that a timeseries() object is not double precision. You need to extract the double precision information from the timeseries object, which involves code similar to
function y = fcn(first_input, second_input)
y = zeros(some size); %pre-allocate
z = some_function_that_returns_timeseries;
y = z.Data; %extract the numeric data from the timeseries
end
However, seeing as you are extracting a time series, I wonder if you are wanting each sample to be... scheduled? ... at the appropriate time? For example if the timeseries had a sample at time 0.1 of -3.5 and a sample at time 0.2 of -2.7 then would you want the -3.5 to become available to the rest of the circuit at time 0.1, and the -2.7 to become available to the rest of the circuit at time 0.2? Or do you want to run the MATLAB function block once and have it emit the vector [-3.5, -2.7] ? Or do you want to do something similar to interpolating the entries in the time series according to the current (simulated) time ?
Is the task to import a timeseries object from the base workspace in the form of a (time-stamped) signal, similar to From Workspace ?
  1 Commento
Mohamed Abdullah
Mohamed Abdullah il 19 Apr 2023
Modificato: Mohamed Abdullah il 20 Apr 2023
What I am exactly doing is that I want the matlab block to work as a controller in my simulink model and to output a control signal. This signal should have both ( data, time).and not only a vector of data.
I have the timeseries whose data and time info are: a vector of size (1X11) of data and time vector of size 1X11 . I want when I run the model is to apply each index of data from the data vector with its corresponding time stamp from the time vector. So that:
1-I can apply the signal to the next module in my model.
2-to be able to see the graph of the signal in the scope block as a timeseries and not just some lines of the data vector.
I tested calling the timeseries returning function from workspace and it works fine
Note: More info about the timeseries returning function The function solves differential equations and obtains the optimal control signal in the form of a vector. This 'u' vector is then placed with time vector 't'by: U= timeseries (u,t);
And U is the returned output.

Accedi per commentare.

Categorie

Scopri di più su Time Series Events in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by