add a vector as a timetable element
显示 更早的评论
Hi,
I would like to write the column of a matrix as element of a timetable (meaning a column for each time). in this timetable I have other variables that have a scalar value at each time. Any suggestion on how to do it?
Cheers,
Giacomo
采纳的回答
Cris LaPierre
2020-12-8
编辑:Cris LaPierre
2020-12-8
A column for each time? Do you mean row?
Just add it as a new variable in your timetable. Each column is typically a separate variable.
indoors = readtimetable('indoors.csv')
indoors = 60x2 timetable
Time Humidity AirQuality
___________________ ________ __________
2015-11-15 00:00:24 36 80
2015-11-15 01:13:35 36 80
2015-11-15 02:26:47 37 79
2015-11-15 03:39:59 37 82
2015-11-15 04:53:11 36 80
2015-11-15 06:06:23 36 80
2015-11-15 07:19:35 36 80
2015-11-15 08:32:47 37 80
2015-11-15 09:45:59 37 79
2015-11-15 10:59:11 36 80
2015-11-15 12:12:23 37 80
2015-11-15 13:25:35 37 79
2015-11-15 14:38:46 36 83
2015-11-15 15:51:58 37 80
2015-11-15 17:05:10 36 80
2015-11-15 18:18:22 37 80
% Create temperatures
tempF = randi(100,[height(indoors),1]);
% Add vector of temperatures to timetable
indoors.Temp = tempF
indoors = 60x3 timetable
Time Humidity AirQuality Temp
___________________ ________ __________ ____
2015-11-15 00:00:24 36 80 75
2015-11-15 01:13:35 36 80 17
2015-11-15 02:26:47 37 79 6
2015-11-15 03:39:59 37 82 92
2015-11-15 04:53:11 36 80 74
2015-11-15 06:06:23 36 80 98
2015-11-15 07:19:35 36 80 72
2015-11-15 08:32:47 37 80 65
2015-11-15 09:45:59 37 79 1
2015-11-15 10:59:11 36 80 84
2015-11-15 12:12:23 37 80 45
2015-11-15 13:25:35 37 79 23
2015-11-15 14:38:46 36 83 65
2015-11-15 15:51:58 37 80 5
2015-11-15 17:05:10 36 80 46
2015-11-15 18:18:22 37 80 10
3 个评论
Thanks for you detail answer but this is not what I am trying to do. Referring to the example:
I would like to add for each time in the initial time table a vector that is the temperature at different heights (and this are stored in a matrix in which each column correspond to a time, this is why I said column but it is not the central part of the problem).
So my table (using your example) would have for each time one value of humidity, one value of air quality and a vector that is the temperature at - lets say 10 - different heights.
This temperatures are stored into a matrix that has a column for each time and a row for each height (so in the example 10 rows and 60 colums).
Hope I managed to explained myself.
Thanks again!
Giacomo
Still not a problem. Can we assume the times in your timtable rows align with the times of your matrix colums?
Updating the example slightly.
% Creating a 60x2 timetable
indoors = readtimetable('indoors.csv');
% Creating a matrix with 4 heights x 60 times (reduced for visual purposes only)
tempF = randi(100,[4,60]);
% Add temps to timetable under a variable Temp
% Transopose tempF so that rows are times, and columns are heights
indoors.Temp = tempF'
indoors = 60x3 timetable
Time Humidity AirQuality Temp
___________________ ________ __________ _______________________
2015-11-15 00:00:24 36 80 4 16 47 59
2015-11-15 01:13:35 36 80 23 3 13 91
2015-11-15 02:26:47 37 79 76 34 90 13
2015-11-15 03:39:59 37 82 76 24 12 41
2015-11-15 04:53:11 36 80 92 76 25 39
2015-11-15 06:06:23 36 80 67 85 37 63
2015-11-15 07:19:35 36 80 20 4 29 68
2015-11-15 08:32:47 37 80 41 60 98 99
2015-11-15 09:45:59 37 79 64 48 15 14
2015-11-15 10:59:11 36 80 56 26 100 31
2015-11-15 12:12:23 37 80 67 74 55 74
2015-11-15 13:25:35 37 79 57 2 46 16
2015-11-15 14:38:46 36 83 84 54 16 35
2015-11-15 15:51:58 37 80 87 21 12 23
2015-11-15 17:05:10 36 80 61 73 34 78
2015-11-15 18:18:22 37 80 69 81 66 73
indoors = splitvars(indoors,'Temp','NewVariableNames',["H1" "H2" "H3" "H4"])
indoors = 60x6 timetable
Time Humidity AirQuality H1 H2 H3 H4
___________________ ________ __________ __ __ ___ __
2015-11-15 00:00:24 36 80 4 16 47 59
2015-11-15 01:13:35 36 80 23 3 13 91
2015-11-15 02:26:47 37 79 76 34 90 13
2015-11-15 03:39:59 37 82 76 24 12 41
2015-11-15 04:53:11 36 80 92 76 25 39
2015-11-15 06:06:23 36 80 67 85 37 63
2015-11-15 07:19:35 36 80 20 4 29 68
2015-11-15 08:32:47 37 80 41 60 98 99
2015-11-15 09:45:59 37 79 64 48 15 14
2015-11-15 10:59:11 36 80 56 26 100 31
2015-11-15 12:12:23 37 80 67 74 55 74
2015-11-15 13:25:35 37 79 57 2 46 16
2015-11-15 14:38:46 36 83 84 54 16 35
2015-11-15 15:51:58 37 80 87 21 12 23
2015-11-15 17:05:10 36 80 61 73 34 78
2015-11-15 18:18:22 37 80 69 81 66 73
Thanks! This was very helpful!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Standard File Formats 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
