How to output a timeseries from matlab function in simulink?
조회 수: 14 (최근 30일)
이전 댓글 표시
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
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
?
답변 (1개)
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 ?
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!