How to separate Variables Names from the Data in Two Different table

Hello,
I have been able to read my excel file and to create my table using this code:
T = readtable('Data.xlsx','TextType','string');
I would like to separate them in 2 differents tables one with variables names and one with the data
because my list of variable name is very long.
like following:
varnames = ["Var1""Var2"..."VarN"]
data =["BOB" "london" "BIM" "Alfred" "Paris" "BOB" "John" "BOB" "CEF"]
Thanks for your understanding
Have a nice day.

 Accepted Answer

Perhaps something like this —
T1 = array2table(randi(99, 10, 5))
T1 = 10×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 66 94 35 1 7 80 65 87 94 7 18 90 14 99 88 23 29 23 14 46 55 58 31 61 57 97 52 61 95 1 55 23 39 27 31 98 5 11 12 88 47 15 55 80 46 83 49 81 31 27
T2 = T1;
T2.Properties.VariableNames = {'Alpha','Beta','Gamma','Delta','Epsilon'}
T2 = 10×5 table
Alpha Beta Gamma Delta Epsilon _____ ____ _____ _____ _______ 66 94 35 1 7 80 65 87 94 7 18 90 14 99 88 23 29 23 14 46 55 58 31 61 57 97 52 61 95 1 55 23 39 27 31 98 5 11 12 88 47 15 55 80 46 83 49 81 31 27
Make appropriate changes to get the desired result.
.

4 Comments

Thanks again...
but I can't get my data alone without variable name at the row heading?
The only way to find out is to do that experiment —
T1 = array2table(randi(99, 10, 5))
T1 = 10×5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 53 6 33 10 29 62 33 89 18 88 6 32 3 56 40 4 5 57 62 92 45 13 96 96 71 78 10 53 51 49 20 53 58 22 65 54 18 10 5 16 23 22 78 34 69 68 57 74 37 42
T2 = T1;
T2.Properties.VariableNames = repmat({' '}, 1, 5)
Duplicate table variable name: ' '.
T3 = T1;
T3.Properties.VariableNames = cell(1,5)
These both fail, for different reasons.
So, regardless of whether the variable names are blanks or are empty, those will fail.
The variable names must be a cell array filled with some sort of unique character vectors.
If the intent is to not have any variable names, then the only option is to use table2array, table2cell, or something similar, depending on what works best in the intended application (and what works best with the contents of the original table array).
.
Clear Ok
Thanks again
Good evening

Sign in to comment.

More Answers (0)

Products

Release

R2016b

Asked:

Ali
on 11 Dec 2021

Commented:

on 11 Dec 2021

Community Treasure Hunt

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

Start Hunting!