how tocreate a new array that select the columns with a specific prefix in the header row

5 vues (au cours des 30 derniers jours)
Hi,
I would like to create a new array that select the columns with a specific prefix in the header row.
In particular you can see my excel file attached. I want to select and put in a new array the columns that have the prefix w-vel (as I indicated in red).
Thank yu in advance

Réponses (1)

Steven Lord
Steven Lord le 17 Avr 2019
Read your data into a table array using readtable. Since I don't have your spreadsheet, I'll just create a sample table using the example in the help text for the table function.
>> load patients
>> patients = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
Retrieve the list of variable names from the patients array. This will include LastName, Gender, Age, etc.
>> tableVariableNames = patients.Properties.VariableNames;
Use startsWith (one of the text processing functions in MATLAB) and indexing to retrieve the variables from patients whose names start with S (Smoker and Systolic.) I'll only retrieve the first ten because the patients array has 100 rows but we don't need that many to see that this works.
>> SmokerAndSystolic = patients(1:10, startsWith(tableVariableNames, 'S'))
If you display the first ten rows of patients, you will see that its Smoker and Systolic variables match the contents of SmokerAndSystolic.
>> patients(1:10, :)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by