How to output a timeseries from matlab function in simulink?
27 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 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
?
Answers (1)
Walter Roberson
on 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 Comment
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!