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

10 Ansichten (letzte 30 Tage)
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'?

Antworten (2)

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

kat001
kat001 am 28 Mai 2018
Bearbeitet: kat001 am 28 Mai 2018
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

Kategorien

Mehr zu Time Series Events finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by