Indexing arrays for two specific values in the same row?

조회 수: 2 (최근 30일)
Adysen
Adysen 2022년 11월 13일
답변: DGM 2022년 11월 13일
Say I have a given array:
array=[4,5,6,7,8;4,6,9,8,1;3,7,4,5,9;6,7,8,1,4]
array = 4×5
4 5 6 7 8 4 6 9 8 1 3 7 4 5 9 6 7 8 1 4
I'm trying to find the location in the array where the first two numbers in the row are equal to 4 and 5. How can I sort the array to get only the row that matches these restrictions?

답변 (1개)

DGM
DGM 2022년 11월 13일
Here's one way:
array = [4,5,6,7,8;4,6,9,8,1;3,7,4,5,9;6,7,8,1,4];
matchedrows = find(all(array(:,1:2) == [4 5],2))
matchedrows = 1

카테고리

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