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

7 ビュー (過去 30 日間)
kat001
kat001 2018 年 5 月 28 日
編集済み: kat001 2018 年 5 月 28 日
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 Center および File ExchangeTime Series Events についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by