Simulink Time Series Model

12 visualizaciones (últimos 30 días)
Shyan Devapriya
Shyan Devapriya el 15 de Sept. de 2020
Comentada: Shyan Devapriya el 9 de Oct. de 2020
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

Respuestas (1)

Nitin Kapgate
Nitin Kapgate el 9 de Oct. de 2020
Editada: Nitin Kapgate el 9 de Oct. de 2020
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 comentario
Shyan Devapriya
Shyan Devapriya el 9 de Oct. de 2020
Thank you so much Nitin, I will utilise this and comment if there are any further issues.
Have a nice day

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by