Find Column Number in Table
古いコメントを表示
I would like to subset a table into columns before a certain variable and columns after that variable. Is there a way to locate a column number within a table? Is there a more clever way to do this?
load patients
BloodPressure = [Systolic Diastolic];
T = table(Gender,Age,Smoker,BloodPressure,'RowNames',LastName);
A = *findColNumber*(T, 'Age'); % Some function that will locate the column number of 'Age'.
T1 = T(:, 1:A);
T2 = T(:, A+1:end);
'patients' is a standard example data set included in R2014a. Entering the command 'load patients' should load the relevant data.
Thanks!
採用された回答
その他の回答 (1 件)
Image Analyst
2014 年 10 月 7 日
You don't need the column number. Just do
ages = T.Age;
3 件のコメント
Robot
2014 年 10 月 7 日
Image Analyst
2014 年 10 月 8 日
編集済み: Image Analyst
2014 年 10 月 8 日
You can get the age column like this:
T = load('patients')
ageColumn = find(ismember(fieldnames(T), 'Age'))
Image Analyst
2014 年 10 月 8 日
Actually T is a structure, so I recommend Mohammad's way.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!