How do I take a small array, keyed by a datetime variable which is a subset of a larger array and replace the values in the larger array with the values from the smaller array?

1 次查看(过去 30 天)
What is the best way to take an table which is keyed by a datetime variable and replace the data in a much larger taable (same variables in both) with the data in the smaller table? The smaller table could fall anywhere in the larger table's date range but the smaller table will be made up of contiguous dates.

采纳的回答

Guillaume
Guillaume 2018-5-14
[isinsmall, where] = ismember(bigtable.datevariable, smalltable.datevariable);
bigtable(isinsmall, :) = smalltable(where, :);
Assuming both tables have the same variable names.

更多回答(2 个)

Ameer Hamza
Ameer Hamza 2018-5-14
If both tables have same variable names, you can insert the small table inside large table much like inserting rows inside the matrix. For example
bigTable = ... % you big table
smallTable = ... % your small table
newBigTable = [bigTable(1:5, :); smallTable; bigTable(5:end, :)];
this will insert small table after 5 rows of the large tables and then insert the remaining large table at the end.
  2 个评论
T4H14
T4H14 2018-5-14
What if instead of simply inserting you actually have to match the dates of the small table to dates in the large table and replace the large table data with the small table data? For example, if the large data set includes dates for every day in 2018 but you want to replace May 1-15 in the large data set with the small data set data?
Ameer Hamza
Ameer Hamza 2018-5-14
In that case, refer to @Guillaume's answer. It will overwrite the values in the big table with values in the small table.

请先登录,再进行评论。


Peter Perkins
Peter Perkins 2018-5-14
The answer might be join, or maybe outerjoin. It might also be synchronize. It's hard to tell from your question.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by