how to filter data based on one value in a column?

조회 수: 83 (최근 30일)
Suresh R
Suresh R 2021년 11월 1일
답변: Cris LaPierre 2021년 11월 1일
how to filter data based on one value in a column. i have 40000 rows and 4 columns. in 4th column i have values 1, 2, 3, 4. i want to filter all records in which the values of the 4th column should only be 3. the data is 40000 X 4 double type.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 11월 1일
use a logical array (Ch 12 in MATLAB Onramp).
A = rand(10,3);
A(:,4) = randi(4,10,1)
A = 10×4
0.7596 0.0937 0.1802 3.0000 0.1846 0.3415 0.3006 4.0000 0.2324 0.8903 0.4734 4.0000 0.8114 0.1004 0.7153 3.0000 0.5624 0.9496 0.5770 1.0000 0.3444 0.0529 0.0754 2.0000 0.1635 0.0971 0.6925 1.0000 0.6909 0.6383 0.7955 3.0000 0.5133 0.3658 0.8523 2.0000 0.1696 0.2123 0.9565 2.0000
idx = A(:,4)==3;
B = A(idx,:)
B = 3×4
0.7596 0.0937 0.1802 3.0000 0.8114 0.1004 0.7153 3.0000 0.6909 0.6383 0.7955 3.0000

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by