How to extract timeseries datasets from Matlab Workspace to 'Matlab function' block in SImulink?

8 次查看(过去 30 天)
The X.mat is a 1x1 double time series consists of Time, TimeInfo, Data and DataInfo. Now, I would like to use a 'From Workspace' block connected to 'Matlab function' block in order to get the Data and Time from the timeseries in Simulink. How to extract the Data and Time from the X.mat as an inputs to the 'Matlab function'?

回答(2 个)

TAB
TAB 2018-5-28
编辑:TAB 2018-5-28
From Workspace (Simin) block directly accepts the time series as input data.
Just replace "simin" with your timeseries variable name.

kat001
kat001 2018-5-28
编辑:kat001 2018-5-28
What I meant was how to read that specific "variable", i.e. 'Data' in Simulink. For example, when opening the Matlab function block, one could see:
function y = fcn(u)
y = u;
Where, u being the X.mat. Now, X.mat has the following info:
>> X
timeseries
Common Properties:
Name: 'X'
Time: [40001x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
*Data: [1x1x40001 double]*
DataInfo: [1x1 tsdata.datametadata]
Here, the Data is what I need to extract using a Matlab function in Simulink, where each Data need to be compared with the previous data.
So, I tried following and not much is happening. I am new to coding, so I appreciate all help.
function y = fcn(X)
out = 0;
for i = 2:length(X)
if(X(i) > X(i-1))
out = ..... + 1;
else
out = ..... - 1;
end
end
y = out;
end

类别

Help CenterFile Exchange 中查找有关 Time Series 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by