Mismatching tables with different sizes and changing the values
Mostrar comentarios más antiguos
Hello,
I am new to Matlab. I have tables (t1 and t2) with different sizes. The tables show datetime with the range of milliseconds (hh:mm:ss.SSS). I showed and example at 09:50:46.676 and 09:50:46.673 and there is only a millisecond difference.
I want to write a code to find the exact same values of hh:mm:ss in both tables and the difference of milliseconds(SSS) is less than abs(10). If the milliseconds difference is less than abs(10), I want to change the time of the table t2 entry as same as table t1.

%[~,~,~,hx,mx,msx]=datevec(t1);
%[~,~,~,hy,my,msy]=datevec(t2);
%idx=find((hx==hy) & (mx==my) & (msy-msx<abs(10)))
But I am facing an error at the end displaying that the sizes are different. And I don't know how to write the code to change the entry of table t2 same as table t1. Can someone help me?
t1=readtable('t1.xlsx','NumHeaderLines',10,'PreserveVariableNames',true);
t2=readtable('t2.xlsx','NumHeaderLines',10,'PreserveVariableNames',true);
[~,~,~,hx,mx,msx]=datevec(t1);
[~,~,~,hy,my,msy]=datevec(t2);
indexX = [];
indexY = [];
for i = 1:size(hx)
for j = 1:size(hy)
if((hx(i)==hy(j)) & (mx(i)==mx(j)) & (abs(msy-msx)<10))
indexX = [indexX; i];
indexY = [indexY; j];
end
end
end
1 comentario
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Timetables en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!