Logical Indexing Data Issue

조회 수: 13 (최근 30일)
Tyler Rolince
Tyler Rolince 2016년 3월 30일
답변: Star Strider 2016년 3월 30일
I'm working on a project where I'm given a large matrix. I'm trying to isolate all third column values that fit into a certain group (ie an array of all values in the third column when column 1 is equal to 5 and column 2 is equal to 4). I've tried using logical indexing to accomplish this but have so far failed. Any help would be greatly appreciated.

채택된 답변

Star Strider
Star Strider 2016년 3월 30일
Logical indexing is the way to go. You need to set the logic up correctly:
This works:
M = randi(9, 1000, 3); % Create Data
M(10, 1:2) = [5 4]; % Be Certain One Row Matches Criteria
Out = M((M(:,1) == 5) & (M(:,2) == 4), 3); % Desired Result

추가 답변 (1개)

Adam
Adam 2016년 3월 30일
편집: Adam 2016년 3월 30일
myMatrix = randi( 10, 1000, 3 );
condition = myMatrix( :, 1 ) == 5 & myMatrix( :, 2 ) == 4;
result = myMatrix( condition, 3 );

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by