MATLAB Answers

Rub Ron

From matrix to timetable

Asked by Rub Ron
on 14 Aug 2019
Latest activity Commented on by Steven Lord
on 14 Aug 2019
I have a matrix bb (class:double), where the first column is the time in numeric format. I want to convert this matrix to a timetable:
I can do it with this line:
But to me does not look optimal as I have to do it for several long matrices inside an array. Is there a better way to do so?


Sign in to comment.


1 Answer

Answer by Neuropragmatist on 14 Aug 2019
 Accepted Answer

I think what you have there is about as efficient as you can get.

  1 Comment

Steven Lord
on 14 Aug 2019
One minor optimization, to reduce typing, would be to make that into a function or an anonymous function. That would at least save you having to retype the parameters to array2timetable repeatedly.
makeTT = @(x) array2timetable(x(:, 2:end), ...
'RowTimes', x(:, 1), ...
'ConvertFrom', 'excel');
y1 = makeTT(x1);
y2 = makeTT(x2);
% etc

Sign in to comment.