필터 지우기
필터 지우기

How to output a timeseries from matlab function in simulink?

조회 수: 21 (최근 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 CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by