How to output a timeseries from matlab function in simulink?

27 ビュー (過去 30 日間)
Mohamed Abdullah
Mohamed Abdullah 2023 年 4 月 19 日
編集済み: Mohamed Abdullah 2023 年 4 月 20 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 19 日
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 2023 年 4 月 19 日
編集済み: Mohamed Abdullah 2023 年 4 月 19 日
Yes, I have the second setup type.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 19 日
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 件のコメント
Mohamed Abdullah
Mohamed Abdullah 2023 年 4 月 19 日
編集済み: Mohamed Abdullah 2023 年 4 月 20 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSources についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by