identify and delete columns from a MATALB table

Hello guys, im new to MATALB and have a small problem. I have a Skript to combine several CSV-Data to a Table with the Name “AllTables”. I want that MATLAB search in this Table (ALLTables) for columns that have in their names the following abbreviations: "Blank, MT_19_Sp, MT_19_3". These columns should be remove and all other columns should stay untouched. The names of these columns are already defined in a Variable called "SampleNames". I received this Skript from a colleague, but unfortunately, the person is now ill. Since am a beginner, I have no idea how to solve this problem. Can u tell me a possible code to solve this problem? I use MATALB 2018.
Greetings .
Carlo

 Accepted Answer

>The names of these columns are already defined in a Variable called "SampleNames".
By 'column names' I assume you mean what Matlab calls "Variable Names" or what are commonly referred to as "headers", the names of each column. Instead of using an independent variable that stores a copy of the variable names, use the table's list of variable names directly. If the names or the order of the columns ever changes, your "SampleNames" will be useless and misleading.
Variable Names are stored in
ALLTables.Properties.VariableNames
To identify which Variable Names contain abbreviations somewhere within their names, use contains() which has an option to ignore case.
If you have any problems, show us what you've got and describe the problem so we can set things straight.

3 Comments

Hello Adam,
i didn't expect such a quick response. Thank you very mutch ! I'm not sure if I expressed myself correctly. In the attached picture you can see a table. I want to remove certain columns from that table. These columns should be recognized by certain strings in their header. For example the abbreviation "Blank" or "MT_19_8".
I tried to implement the suggestion you made as follows:
removesamples = contains(AllTables.Properties.VariableNames,["Blank_" "MT_19_1" "MT_19_8" "MT_19_15" "MT_19_22" "MT_19_29" "MT_19_36" "MT_19_Sp" "MT_19_34"],"IgnoreCase",true)
removesamples =
1×37 logical array
Columns 1 through 33
0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 1 1
Columns 34 through 37
1 0 1 0
So I could identify the columns, and recived an array with 0 and 1,but i still need to delete the identified columns. With IgnoreCase i can Index back...and that menas the colums are deleted ?? So i used str(TF) in the form of:
AllTables(removesamples)
and recived an error:
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported. Use a row subscript and a variable subscript
Best regards,
Carlo
The logical array identifies the columns tto be removed. To remove those columns
removesamples = contains(__);
AllTables(:, removesamples) = [];
Oh in the end it was so easy. Thank you very mutch Adam !

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!