IT

Matlab, 한 column에서 특정 값을 갖는 모든 rows 얻기

라이꼬끼 2019. 5. 29. 21:46

Matlab에서, 이런 경우가 생긴다.

 

"첫 번째 column이 2인 모든 rows를 얻고 싶다."

"시간을 나타내는 column에서, 5시인 경우의 데이터만 얻고 싶다."

 

한 column에서 특정 값을 가지는, 모든 rows를 얻고 싶을 때가 생긴다.

 

다음과 같이 논리 인덱스(logical index)를 이용한다.

A = [1 0.1 0.3 0.5;2 0.2 0.5 0.7;1 0.3 0.5 0.8;2 0.1 0.2 0.3];
B = A(:, 1) == 2;
C = A(B, :)

더 간단하게는 다음과 같다.

C = A(A(:, 1) == 2,:);​

 

https://mathworks.com/matlabcentral/answers/2381-accessing-matrix-rows-using-logical-indexing

 

Accessing Matrix Rows using Logical Indexing - MATLAB Answers - MATLAB Central

This is probably a very simple question to answer, and I'm sure its been asked a million times, but I just can't seem to find an answer that works for me. Let's say I have an array like this: A = [1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4]; A = 1 1 1 1 2 2 2 2 3 3 3

kr.mathworks.com