Why am I getting an error when trying to linear index into my table?
>> load patients
>> T = table(Gender,Smoker,Height,Weight);
>> T(:,4)(T.Smoker==1)
Error: ()-indexing must appear last in an index expression.

 采纳的回答

The syntax being used is trying to index into a table that has already been indexed into. Instead, index only once to get the desired behavior:
>> T(T.Smoker==1, 4)
Alternatively, this can be broken up into two lines of code:
>> temp = T(:,4);
>> temp(T.Smoker==1,:)

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

版本

R2018a

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by