Simulink Time Series Model

조회 수: 7 (최근 30일)
Shyan Devapriya
Shyan Devapriya 2020년 9월 15일
댓글: Shyan Devapriya 2020년 10월 9일
Hi All,
I want to use Simulink to input a set of time stamped temperature data. I have been trying to use the from workspace block to do this after converting the data I extracted from excel into a timetable. The timestamp data is a record of ambient temperature that is taken every 5 minutes for a month and is in the following format - yyyy:mm:dd:hh:mm:ss.
First of all, is it possible to use simulink to get a model in which specific temperature will be fed into a sink or bus every 5 minutes for a month? Or am I looking in the totally wrong place in terms of modelling?
Any help is appreciated.
Kind regards
Shyan

답변 (1개)

Nitin Kapgate
Nitin Kapgate 2020년 10월 9일
편집: Nitin Kapgate 2020년 10월 9일
You can refer to the attached Simulink model for reference and suitably modify the model to solve your problem.
The attached model provides functionality to use the temperature data from the timeseries object as input to the Simulink model.
The data required for the model to work is created in the MATLAB's base workspace using the ‘InitFcn’ model callback. You can access and modify the ‘InitFcn’ callback from the model properties.
The following code is executed in the ‘InitFcn’ callback function:
% This code loads all the required data and variables to the base workspace
load outdoors; % Load inbuilt MATLAB timeseries object from an inbuilt .MAT file
outdoors.Properties % Display the Time Table's properties.
rowsInTimeTable = numel(outdoors.Properties.RowTimes); % Get number of rows in the timetable
timeData = outdoors.Time(:); % Extract the time data from timedata
temperatureData = outdoors.TemperatureF(:); % Extract the temperature data from the timetable
startTime = datetime(timeData(1)); % Get the start time
timeInHrMinSec = timeData - startTime; % Convert the time data to elapsed time, now the time starts as 00Hr:00Min:00Sec
timeInSeconds = seconds(timeInHrMinSec); % Convert the time form HH:MM:SS to seconds. which is suitable for use in Simulink
t = timeInSeconds; % This is the time input taken by simulink from Simulink
tempData = temperatureData; % This is the corresponding temperature column vector, taken as the first data input used by Simulink
stopTime = t(rowsInTimeTable); % Use this value as the Simulation Stop Time
You will need to make the following changes to the model:
  1. In Model Configuration Parameters (Press CTRL+E to open), under Data Import/Export settings, Check the box against input under the Load from Workspace option. Enter the input as [ t, tempData] where “t” is a column vector of time (in seconds) and "tempData" is a column vector of temperature data. This data will get loaded from the workspace. The variable tempData corresponds to the input port 1.
  2. In Solver options, make the following changes:
  • Change the solver to Fixed-step auto solver.
  • Change the step-size to 5400 seconds (In your case, this will be 300 seconds as your data gets updated every 5 minutes)
  댓글 수: 1
Shyan Devapriya
Shyan Devapriya 2020년 10월 9일
Thank you so much Nitin, I will utilise this and comment if there are any further issues.
Have a nice day

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by