Simulink Time Series Model
26 次查看(过去 30 天)
显示 更早的评论
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 个评论
Muhammad
2024-5-16
Choose the appropriate weather station (2 points)
- extract the station name, elevation, latitude and longitude data for each station in the NOAA spreadsheet Download NOAA spreadsheetOpen this document with ReadSpeaker docReaderinto another spreadsheet
- add the data for Walnut CA to it (Google it!).
- write a script that reads the spreadsheet and uses geoplot with the colorterrain basemap to plot the data. Do not use a semicolon when reading the spreadsheet so that the console will output what you read.
- select the station with the best fit visually based on terrain and proximity to Walnut
- add text labels to the plot at the station location and Walnut, and add a title
- (UPLOAD #1) publish the script with the output option set to PDF
2) Extract and sanitize the selected station's data (2 points)
- extract the selected station daily date, max and min temp data temperature into another spreadsheet
- write a script that reads the spreadsheet and plots Tmax, Tmin, and (computed) Tavg (the average of Tmax and Tmin) on the same graph to see if their are any anomalies (outlier data and/or bad sensor data [ = temp is -9999 ] and remove them from the spreadsheet if they exist. Use the temperature vector's index as the x-axis values.
- (UPLOAD #2) add any additional information to the plot to make it an engineering plot and publish the script with the output option set to PDF
3) Curve fit the temperature data (6 points)
- write a script that reads Tavg from the spreadsheet in #2. Then create a time vector in hours with the same length as Tavg starting with 0 (i.e. the first time will become 0, the second 24, the third 48, and so on - hint there is formula you can develop to do this based on the length of Tavg). Then have the script run fit() for 1, 5, and 8 sinusoids using Tavg and plot each along with the original Tavg data on the same plot (use points for the original data and curves for the fit() models). Create a legend in the South-East location that includes labels indicating the number of sinusoids and the value for R squared (note - create the label with sprintf).
(UPLOAD #3) - add any additional information to the plot to make it an engineering plot, output the selected fit object (i.e. just have a line with the object name and no semicolon), and publish the script with the output option set to PDF
4) Create a Simulink model for your temperature data (4 points)
- create a Simulink model for your modeled data using sine sources in a subsystem block
- (UPLOAD #4) create a plot of your Simulink model in PDF
- (UPLOAD #5) create an engineering plot with your Simulink model temperature output, chosen fit model, and the original Tavg data and save it as PDF.
NEED HELP WITH PART 3-4-5
回答(1 个)
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:
- 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.
- 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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/375726/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!