Creating new table from another table

65 views (last 30 days)
i have following problem. I have a 35049x297 table. Now i would like to cut out specific columns with an if command and put these columns in a new table.
VarNames = Daten2.Properties.VariableNames;
for i = 1:columns
if contains(VarNames{1,i},'EN')
newtable{i} = table(Daten2.VarNames{1,i});
This is my code but it doesnt work, i dont know why? can someone help me with that? Thanks for the help!!!
Benedikt Skurk
Benedikt Skurk on 26 May 2021
Ok i got it..
But the last problem i have is that he doesnt transfer the column headers.
so for example first column header is PE EN Neuruppin_1 and second header is PE EN Wittst_3
U have a solution for that?

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 26 May 2021
Edited: Scott MacKenzie on 26 May 2021
You have several problems in your code. The assumtion in your question is that you want to create a new table (newtable) containing columns in the existing table (Daten2) where 'EN' appears in the column name. Here's one way to acheive this:
VarNames = Daten2.Properties.VariableNames;
columns = width(Daten2);
j = 1;
for i = 1:columns
if contains(VarNames{i}, 'EN')
newtable(j) = Daten2(:,i);
newtable.Properties.VariableNames{j} = VarNames{i};
j = j + 1;

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!