Logical operation with multiple conditions

19 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 30 Jul 2022
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!