add a vector as a timetable element
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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')
% Create temperatures
tempF = randi(100,[height(indoors),1]);
% Add vector of temperatures to timetable
indoors.Temp = tempF
3 个评论
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 = splitvars(indoors,'Temp','NewVariableNames',["H1" "H2" "H3" "H4"])
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!