How a table columns are named using MATALB

I have a fetaure table with 5*10 size.Now I woul like to name each of the Coloumns
I would like to name ecah coloumn and also again 5 coloumn need to give name with Title1 as shown below.Please help me using MATLAB

1 个评论

Adding "headers" (i.e. column/variable names) is easy if you convert the data to a table: https://www.mathworks.com/help/matlab/ref/array2table.html
However a heirarchy of column/variable names like you show is not possible in one table :https://www.mathworks.com/matlabcentral/answers/541568-nested-tables-with-duplicate-sub-column-names
You could create nested tables, but that does complicate accessing and processing your data.

请先登录,再进行评论。

 采纳的回答

Something like the following may be similar to what you want.
clear; clc;
combine_vector = randi(10,5,10);
Title1 = array2table(combine_vector(:,1:5),'VariableNames',compose('feature%d',1:5));
Title2 = array2table(combine_vector(:,6:10),'VariableNames',compose('Sfeature%d',1:5));
T = table(Title1,Title2)
T = 5×2 table
Title1 Title2 feature1 feature2 feature3 feature4 feature5 Sfeature1 Sfeature2 Sfeature3 Sfeature4 Sfeature5 ________________________________________________________ _____________________________________________________________ 1 9 10 6 3 5 2 9 2 4 3 10 4 8 10 4 10 10 4 4 2 6 1 8 7 4 7 5 8 5 6 2 2 8 7 2 6 8 6 2 6 6 10 2 9 2 4 8 2 8

8 个评论

Thanks for the response.If tha table is of Size 28*75. If we want to Write first 5 columns are Enrgy1,variance1,Standard Deviation1,Waveform length1,Entrophy1 and next 5 feature with Energy2 so on for 75 coloums and again each 5 coumns needd to be named as H1 to H15.How does we implement using MATLAB.
Please refer to the following:
As mentioned by Stephen, it becomes a little bit complicated.
clear; clc;
Nz = 15;
combine_vector = randi(10,28,75); % Simulate data
TopTitle = compose('H%d_Features',1:Nz); % Prepare the top title
SubTitle = ["Energy","Variance","Standard_Deviation","Waveform_Length","Entrophy"]; % Prepare the sub title
%
T = cell(1,Nz);
for k = 1:Nz
Ttemp = array2table(combine_vector(:,5*(k-1)+1:5*(k-1)+5),'VariableNames',strcat(SubTitle,num2str(k)));
T{k} = table(Ttemp,'VariableName',TopTitle(k));
end
Tcombine = cat(2,T{:});
Tcombine(:,1:3) % Table is too big and just display the first 3 columns
ans = 28×3 table
H1_Features H2_Features H3_Features Energy1 Variance1 Standard_Deviation1 Waveform_Length1 Entrophy1 Energy2 Variance2 Standard_Deviation2 Waveform_Length2 Entrophy2 Energy3 Variance3 Standard_Deviation3 Waveform_Length3 Entrophy3 ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ 1 2 1 8 4 8 6 7 3 10 4 8 9 8 2 7 9 5 10 4 10 9 10 10 9 8 5 10 8 7 5 4 10 6 5 7 2 1 4 8 9 4 8 5 10 9 6 9 4 1 9 2 4 3 10 6 4 4 9 10 8 9 5 7 3 8 7 8 9 5 4 6 4 6 3 5 4 3 2 4 5 4 4 10 9 5 7 10 8 6 3 8 10 8 8 6 7 9 4 4 8 3 9 5 9 8 1 10 8 9 4 3 10 7 8 3 5 2 3 6 5 5 4 5 2 9 7 9 1 7 2 10 10 4 4 6 3 4 1 4 3 2 8 3 6 3 5 4 5 1 1 1 4 8 4 2 2 4 2 9 5 9 8 4 9 5 6 8 6 4 1 5 5 9 6 1 2 5 3 5 7 1 4 7 6 1 7 3 7 2 9 5 6 10 5 3 3 2 9 7 9 7 10 6 1 4 1 3 8 5 10 3 2 4 3 10 8 9 7 9 4 1 5 7 9 8 1 3 1 5 6 9 3 4 7 1 1 10 3 3
I'm so glad for your response sir.But if I run this code in matlab2018a, I got error at
"Ttemp = array2table(combine_vector(:,5*(k-1)+1:5*(k-1)+5),'VariableNames',strcat(SubTitle,num2str(k)));"
The Error is
Plese help me with this.Iam so thankful to you sir
Could you please upload your code regarding varaibles 'TopTitle' and 'SubTitle'.
Rather than putting everything into one line, simply define all of the input arguments as variables:
arr = combine_vector(..);
vnm = strcat(..);
Ttemp = array2table(arr,'VariableName',vnm)
Not only will you have neater and clearer code, but you can then easily check the input arguments yourself: you will find that variable names are not a cell array of character vectors, just as the error message states.
Thank you so much sir.If I wolud like to save all titles first columns to one variable and all second coloumns to another variable and so on.
A=Title1.features1(:,1)
B=Title1.Sfeatures2(:,2)
I can use these but if I have a 12*15 size and I wolud like to save 1,6,11 coumns data to one variable and 2,7,12 to another variable ,3,8,13 and 4,9,14 and 5,10,15 to another variable using any loop.Please help me with this sir
clc
clear all
close all
X=randi(10,12,75);
Nz = 15;
TopTitle = compose('H%d_Features',1:Nz); % Prepare the top title
T = cell(1,Nz);
for k = 1:Nz
arr=X(:,5*(k-1)+1:5*(k-1)+5);
vnm =strcat({'Energy','variance','std','wl','entrophy'},num2str(k));
Ttemp = array2table(arr,'VariableNames',vnm);
T{k} = table(Ttemp,'VariableName',TopTitle(k));
end
Tcombine = cat(2,T {:});
Prasad=Tcombine(:,1:Nz);
%% Channel1 features %%
s11=Prasad.H1_Features(:,1);
s12=Prasad.H2_Features(:,1);
s13=Prasad.H3_Features(:,1);
s14=Prasad.H4_Features(:,1);
s15=Prasad.H5_Features(:,1);
%% Channel2 Features %%
s21=Prasad.H1_Features(:,2);
s22=Prasad.H2_Features(:,2);
s23=Prasad.H3_Features(:,2);
s24=Prasad.H4_Features(:,2);
s25=Prasad.H5_Features(:,2);
%% Channnel3 Features %%
s31=Prasad.H1_Features(:,3);
s32=Prasad.H2_Features(:,3);
s33=Prasad.H3_Features(:,3);
s34=Prasad.H4_Features(:,3);
s35=Prasad.H5_Features(:,3);
%% Channel4 Features %%
s41=Prasad.H1_Features(:,4);
s42=Prasad.H2_Features(:,4);
s43=Prasad.H3_Features(:,4);
s44=Prasad.H4_Features(:,4);
s45=Prasad.H5_Features(:,4);
%% Channel5 Features %%
s51=Prasad.H1_Features(:,5);
s52=Prasad.H2_Features(:,5);
s53=Prasad.H3_Features(:,5);
s54=Prasad.H4_Features(:,5);
s55=Prasad.H5_Features(:,5);
I want to use a loop to save channel 1 feature into one variable and like wise all the featutres sir.Please help me with the help of any loop function
There is no need to save them in different variables. Stephen's recommendation is absolutely right.
In case you would like to use data on column 1,6,11. You can directly retrieve them from the variable combine_vector as follows:
combine_vector = randi(10,28,75);
combine_vector(:,[1 6 11])
ans = 28×3
8 4 10 9 6 10 1 7 1 9 7 4 8 3 2 5 2 6 8 3 10 3 8 4 10 10 10 4 3 8

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by