(How) Can I access multiple columns of a table using colon between their (string) lables (variable names)?

Say I have the following table T:
T=table;
T.Name={'Alice';'Bob';'Mallory'};
T.Age=randi([18 80],3,1);
T.Salary=randi(100,3,1);
T.Weight=randi([60 90],3,1);
T.Height=randi([150 200],3,1);
I know that I can access a span of columns if I know their index, e.g., T(:,3:5) for sub-table or T{:,3:5} for direct access to the elements therein, and obviously, I can explicitly mention their variable names, as in T(:,{'Salary','Weight','Height'}), but can I use their variable names and colon to specify a span of columns? (something like: T(:,{'Salary' [through] 'Height'}) - I think you could do that in R for instance. But does Matlab have such a feature too? So far, the only workaround that I could think of is the following:
T(:,find(strcmp(T.Properties.VariableNames,'Salary')):find(strcmp(T.Properties.VariableNames,'Height')))
Is there a more efficient way of going about it? Thanks!

댓글 수: 1

My thought was that that conceptually when you use the names, the columns are unordered. I could be wrong about that.

댓글을 달려면 로그인하십시오.

답변 (1개)

Arman, there may be a more compact way to write it using ismember, but that is more or less the right way to do what you want.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 10월 25일

답변:

2015년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by