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 件のコメント
giacomo labbri
2020 年 12 月 9 日
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
Cris LaPierre
2020 年 12 月 9 日
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
giacomo labbri
2020 年 12 月 9 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
