How can I convert a string matrix into a table?

200 visualizaciones (últimos 30 días)
Edoardo Giusto
Edoardo Giusto el 24 de En. de 2018
Respondida: Edoardo Giusto el 29 de En. de 2018
I have a MxN matrix made of strings and I would like to convert it into a table because I need to have a timetable object in the end. My variable is a 720x2 strings, the first column contains the timestamp and the second contains a integer value.
This is an example of a row:
19/12/2017 00:00:00 116
I have tried using array2table and cell2table but I was not able to succeed.
I created a workaround, which is to write a file and then read it with readtable, but this way is definitely not immediate.
Thanks in advance, Edoardo

Respuestas (2)

Julia Antoniou
Julia Antoniou el 26 de En. de 2018
Hi Edoardo,
I believe you could accomplish the output you are describing with the following commands (with "matrix" being your matrix of strings):
>> Dates = matrix(:,1);
>> Data = matrix(:,2);
>> T = table(Dates,Data)

Edoardo Giusto
Edoardo Giusto el 29 de En. de 2018
Hi Julia, thanks for your help. I am doing:
Dates = matrix(:,1 );
Data = matrix(:,2 );
T = table(datetime(Dates),Data);
TT = table2timetable(T);
But in the Data column in my timetable values are stored as strings, so with quotes, such as: "116" for instance. In this way I cannot perform some operations (such as averaging).
I am missing some trivial thing I cannot understand at the moment.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by