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

5 ビュー (過去 30 日間)
SYML2nd
SYML2nd 2019 年 4 月 17 日
回答済み: Steven Lord 2019 年 4 月 17 日
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

回答 (1 件)

Steven Lord
Steven Lord 2019 年 4 月 17 日
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, :)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by