Call vector by key
1 view (last 30 days)
Show older comments
I would like to save some weather data in a container. The data consists of forecasts and actuall values for the years 2016-2018. To acces the data I want to use the years as a key, so when I call
windSpeedForecast(2016)
it will give me a vector with all hourly windSpeedForecasts of 2016, so a 8760x1 vector.
The default containers in Matlab are only able to save scalars as values and not vectors. Is there a way to achieve this or am I missing something in the containers.Map object?
Thanks in advance.
Best regards,
Stefan
0 Comments
Accepted Answer
Bruno Luong
on 3 Aug 2020
Work for me
>> M=containers.Map('KeyType','double','valueType','any')
M =
Map with properties:
Count: 0
KeyType: double
ValueType: any
>> M(2020)=double('Covid')
M =
Map with properties:
Count: 1
KeyType: double
ValueType: any
>> char(M(2020))
ans =
'Covid'
>>
4 Comments
More Answers (1)
Steven Lord
on 4 Aug 2020
Depending on what else you want to do with this data, storing it in a timetable may be useful. Using one of the examples on the documentation page for timetable:
MeasurementTime = datetime({'2015-12-18 08:03:05';'2015-12-18 10:03:17';'2015-12-18 12:03:13'});
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
TT = timetable(MeasurementTime,Temp,Pressure,WindSpeed)
Now let's retrieve all the rows with times between 9 AM and 1 PM on the date in question:
selectedTimes = timerange(datetime('2015-12-18 09:00:00'), datetime('2015-12-18 13:00:00'));
X = T(selectedTimes, :)
This particular example does not include any non-scalar data, but it is possible to store such data in a timetable variable.
0 Comments
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!