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
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!