use logical indexing to access multiple lines syntax

조회 수: 1 (최근 30일)
Hew McKean
Hew McKean 2018년 9월 28일
댓글: Hew McKean 2018년 9월 28일
Still a noob, I try to make my questions coherent... glad to learn
I have a multi-column matrix p552r1_tnL (14918x44 double)
In the second column, I want to find the highest values, so I did this...
>> p = (p552r1_tnL(:,2))>0.85*max(p552r1_tnL(:,2));
>> sum(p)
% sum(p) is 40 so getting the highest 40 values is a good start... so that gets my matrix way down,
now I just want to get the values in the first three columns of p552r1 based on that logical matrix... I can get it to give me a single column, but can't work out how to get multiple...
p552r1kmeans = p552r1_tnL(p); %ok, so it gets me one column
So I've tried
p552r1kmeans (:,1:3)= p552r1_tnL(p); %Error: matrix sides don't match
p552r1kmeans (:,1:3)= p552r1_tnL(:,1:3)(p); %Error: ()-indexing must appear last in an indexing expression, which I don't get since (p) is last
Thank you for the help : )

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 9월 28일
temp=p552r1_tnL(p,1:3)

추가 답변 (1개)

Dennis
Dennis 2018년 9월 28일
Almost there ;) in p you have the row positions:
p552r1kmeans=p552r1_tnL(p,1:3)

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by