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 Events에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by