add a vector as a timetable element
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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)
