Separating an array based on row data?

I have an array consisting of 3 columns and 'x' number of rows. Let's call it "Original_Data".
"Original_Data" contains rows where there are values of '0' and I wish to split my array into two new arrays:
  • "Bad_data" will be an array consisting of the original 3 columns from "Original_Data" and all rows from "Original_Data" which contain values of '0'
  • "Good_data" will be an array consisting of the original 3 columns from "Original_Data" and all rows from "Original_Data" which do not contain values of '0'
How would I do this?

답변 (1개)

Jan
Jan 2022년 3월 15일
Data = randi([0,3], 4, 3) % Some Test data
Data = 4×3
1 0 1 0 2 3 0 0 2 2 1 1
good = all(Data, 2); % No zeros in a row
goodData = Data(good, :)
goodData = 1×3
2 1 1
badData = Data(~good, :)
badData = 3×3
1 0 1 0 2 3 0 0 2

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 3월 15일

답변:

Jan
2022년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by