How to split column of a table?

Hello everyone,
I want to split a multi-column of a table into several columns and I tried to use
newtable = splitvars(tbl);
% or
newtable = splitvars(tbl, 'Multico');
But I got this error
Undefined function or variable 'splitvars'.
Could you suggest an alternative to this method?
I'm using MATLAB R2017b.
Many thanks,

4 Commenti

Andy
Andy il 19 Dic 2019
splitvars was introduced in R2018a so would not appear in your version.
Do you know any alternative that can work on R2017b?
Adam Danz
Adam Danz il 19 Dic 2019
Could you explain in more detail what the inputs and expected outputs would be? Maybe provide an example.
Please check the attached file.
It contains a table with 2 main columns, the first one is datetime and the second one should be splitted into 11 columns.

Accedi per commentare.

 Risposta accettata

Adam Danz
Adam Danz il 19 Dic 2019
Modificato: Adam Danz il 19 Dic 2019
T = [omni(:,1), array2table(omni.Var2)];
% Specify VariableNames if you wish
% T = [omni(:,1), array2table(omni.Var2,'VariableNames',{. . .})];
Results
head(T) % show first few rows
ans =
8×12 table
omni_datetime Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11
____________________ ____ ____ ____ ____ _____ ____ ____ _____ ____ _____ _____
01-Jan-2013 00:00:00 2.4 2.2 -0.6 -0.4 44561 1.6 358 0.054 0.42 2 4
01-Jan-2013 01:00:00 2.5 1.8 -1.4 -0.5 37181 2.1 355 0.046 0.52 2.31 4
01-Jan-2013 02:00:00 2.8 2.2 -1.6 -0.4 28131 1.8 359 0.033 0.44 1.49 3
01-Jan-2013 03:00:00 3 2.8 -1.1 0 24936 1.9 352 0.032 0.44 1.35 2
01-Jan-2013 04:00:00 3 2.5 -1.6 0.4 23930 2 351 0.033 0.47 1.41 1
01-Jan-2013 05:00:00 3.1 2.5 -1.4 0.8 22626 2.1 349 0.036 0.49 1.37 3
01-Jan-2013 06:00:00 3 2.6 -1.3 0.8 23016 2.2 343 0.038 0.5 1.54 1
01-Jan-2013 07:00:00 3 2.4 -1.8 0.6 24192 2.3 341 0.038 0.51 1.62 0

11 Commenti

It works!
Thank you very much
Adam Danz
Adam Danz il 19 Dic 2019
Glad I could help!
Hi Adam, please do you know how to convert a table column into a datetime column?
Kindly check the attached file.
Adam Danz
Adam Danz il 20 Dic 2019
Modificato: Adam Danz il 20 Dic 2019
Are you asking how to extract the data from the table column?
dateTimeColumn = dSOHO.datetimeC2;
Yes it works :)
I just need also to convert this time format to UT please, like this:
timeformats.png
My answer moved here as a comment
Mohamed Nedal's reply
Yes I tried it but still it doesn't work.
Here's what I wrote
t = {'12:24:05'
'10:36:05'
'04:07:55'
'01:25:51'
'01:48:05'};
t_final = datetime(t,'Format','hh:mm:ss');
t_final =
23×1 datetime array
12:24:05
10:36:05
04:07:55
01:25:51
01:48:05
t_final.Format = 'default';
t_final =
5×1 datetime array
20-Dec-2019 00:24:05
20-Dec-2019 10:36:05
20-Dec-2019 04:07:55
20-Dec-2019 01:25:51
20-Dec-2019 01:48:05
I get the date of today with the time format I need. I tried to extract only the time but it gives the previous format (am/pm).
I didn't find the answer in that link :) I need to change the format to be like this
t_final = {'00:24:05'
'10:36:05'
'04:07:55'
'01:25:51'
'01:48:05'};
% which is the 24-hr format.
Adam Danz
Adam Danz il 20 Dic 2019
Let's continue the discussion in that thread.
I tried to include an AM PM in the input but still the same. Maybe it's a glitch in my matlab version. I will do it in excel.
Thank you!
The AM/PM needs to be specified in the actual time-values.
t_final = {
'00:24:05 AM'
'10:36:05 AM'
. . .
};

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Prodotti

Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by