MATLAB Answers

add a vector as a timetable element

2 views (last 30 days)
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

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Dec 2020
Edited: Cris LaPierre on 8 Dec 2020
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 Comments
giacomo labbri
giacomo labbri on 9 Dec 2020
Thanks! This was very helpful!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by