Logical operation with multiple conditions

조회 수: 19 (최근 30일)
Max Ventre
Max Ventre 2022년 7월 30일
댓글: Walter Roberson 2022년 7월 30일
I have an 36000x20 table containing both numerical and text data.
I want to add an additional column at the end in which individual rows are evaluated based on some conditions, outputting a 'true' (1) or 'false' (0).
Below is a small section of the data I'm working with.
Easting Northing Chainage SeabedElev VegElev FirstElev Classification VegHeight VegDensity BS Sg SL1 SL2 SS1 SS2 R Sna Unclear Coverage ImageID
__________ __________ ________ __________ _______ _________ ______________________ _________ __________ ___ ___ ___ ___ ___ ___ ___ ___ _______ ________ ____________
6.9623e+05 5.5368e+06 8713.7 49.8 50.025 50.325 {'vegetation(strong)'} 0.525 0.598 1 1 0 0 0 0 0 0 0 80 {'G0068900'}
6.9623e+05 5.5368e+06 8714 49.75 50.175 50.3 {'vegetation(strong)'} 0.55 1.13 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8714.5 49.7 50.2 50.225 {'vegetation(strong)'} 0.525 0.289 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8714.9 49.7 NaN 49.775 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8715.3 49.675 NaN 49.75 {'bareseabed' } 0 NaN 1 1 0 0 0 0 0 0 0 50 {'G0068901'}
6.9623e+05 5.5368e+06 8715.7 49.625 NaN 49.725 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8716.1 49.6 NaN 49.725 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8716.5 49.625 NaN 49.725 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8716.9 49.625 NaN 49.7 {'bareseabed' } 0 NaN 1 0 0 0 0 0 0 1 0 40 {'G0068902'}
6.9623e+05 5.5368e+06 8717.4 49.65 NaN 49.725 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
6.9623e+05 5.5368e+06 8717.8 49.675 NaN 49.725 {'bareseabed' } 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN {'-' }
Many of the rows in columns 10:20 have no data (NaN) and therefore won't need to be evaluated (I.e. in columns 10:19, only the rows containing numerical data need to be evaluted). For this I assume I need to use a for loop with a find function?
When a valid row is found, I want to perform a logical operation for the data in that row and also some data from additonal rows above and below the current row, repeating the steps for subsequent rows.
Simplified example:
(1) Find row where cell in column 10 is NOT NaN
(2) (IF text in column 7 is 'vegetation(strong)' AND value in column 19 is NOT NaN OR NOT 0) OR (IF text in column 7 is 'bareseabed' AND value in column 19 is 0), TRUE
(3) OR (IF text in column 7 is 'vegetation(strong)' AND value in column 19 (in any of the 4 rows above & below current row) is NOT NaN OR NOT 0) OR (IF text in column 7 is 'bareseabed' AND value in column 19 (in any of the 4 rows above & below current row) is 0), TRUE
(4) All else FASLE
(5) Store logical data (result) in new column
Any help is greatly appreciated!
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 7월 30일
mask = ~any(ismissing(YourTable), 2)
mask is now true for rows of the table that have no missing values. No loop is needed to figure out which ones they are.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by