add a vector as a timetable element
1 view (last 30 days)
Show older comments
giacomo labbri
on 8 Dec 2020
Commented: giacomo labbri
on 9 Dec 2020
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
0 Comments
Accepted Answer
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')
% Create temperatures
tempF = randi(100,[height(indoors),1]);
% Add vector of temperatures to timetable
indoors.Temp = tempF
3 Comments
Cris LaPierre
on 9 Dec 2020
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 = splitvars(indoors,'Temp','NewVariableNames',["H1" "H2" "H3" "H4"])
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!