how tocreate a new array that select the columns with a specific prefix in the header row
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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, :)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!