필터 지우기
필터 지우기

Call vector by key

조회 수: 1 (최근 30일)
Stefan M
Stefan M 2020년 8월 3일
답변: Steven Lord 2020년 8월 4일
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

채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 3일
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
Walter Roberson
Walter Roberson 2020년 8월 4일
Stefan: make sure you use 'ValueType', 'any'
Stefan M
Stefan M 2020년 8월 4일
Hi Bruno,
thanks for the clarification. I misread your example and did forget to pass 'ValueType', 'any'. Now it works
@Walter thank you, too

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 8월 4일
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.

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by