MATLAB: How to fill in cells of a table with cells of another table while the two tables do not share the same number of rows

MATLABtable

Hello everybody,
I wonder how I could fill in the cells of one of my tables with the cells of another table, while they do not have the same format.
The first table has quite a regular time (I have data every (more or less) 10ms) and I would like to fill in a column I have created in this table with the content of the second table.
The second table has got data linked to durations: I have a column with the beginning time and another column the ending time of the data.
I tried in two main ways (with several formulations) to create a condition following the idea: "when time of table 1 is above or equal to the starting time of table 2 & if the time of table 1 is under or equal to the ending time of table 2, I want the cells of the column A from table 1 to get the content of the cells of the column A of table 2 at the corresponding times"
Attempt 1
if (Table_1.Time >= Table_2.Time_Start) && (Table_1.Time <= Table_2.Time_End)
Table_1.ColumnA=Table_2.ColumnA
end
Attempt 2
Table_1.ColumnA((Table_1.Time >= Table_2.Time_Start) & (Table_1.Time <= Table_2.Time_End)) = Table_2.ColumnA((Table_1.Time >= Table_2.Time_Start) & (Table_1.Time <= Table_2.Time_End))
In each case, I get the error message "matrix dimensions must agree".
Sorry for being such a beginner, but I do not find a way to solve this issue on my own… could you provide me with some help?

Best Answer

Let's give it a try. I have created a working example with two excel files. This code finds the 'event' in Table2 associated with the time given by Table1, and adds it as an additional parameter to Table1.
Table1=readtable('Table1.xls')
Table2=readtable('Table2.xls')
for i=1:length(Table2.TimeStart)
Table1.Event((Table1.Time>=Table2.TimeStart(i) & Table1.Time<=Table2.TimeEnd(i)))=Table2.Event(i)
end
Is that what you need?