How to use an an if statement which has two criteria to be met to create a new table

7 views (last 30 days)
(apologies if the explanation is hard to follow - I'm struggling to describe it!)
I have a table and I want to create a sub-table of it, if a certain criteria is met.
There are two criteria, either of which is sufficient to join the new table: 1) if the value in one column 1 meet a certain critera, or if the value in column 1 doesn't meet the criteria but the value in column 2 does meet a new criteria.
To expand on the data and the challenge I've attached a photo of the data in a simplified format (and the new table that I am trying to create - with eliminated columns in red).
I have water stress data (where 1 = not stressed, 2 = moderately stressed, 3 = stressed) and flooding risk data (where the number represents increased flooding risk) for ten parcels of land. I want to create a table where all the data are either not stressed (water stress value < 2) or water stress values are above 1 but flooding risk are non-zero.
I've tried a few options using the conditionals but not really made any progress - any help would be greatly appreciated - thanks!Matlab_question_picture.png

Accepted Answer

dpb
dpb on 14 Mar 2019
>> W=[1 2 1 2 1 3 2 0 0 2].';
>> F=[0 0 2 2 0 0 3 3 0 0].';
>> ix=(W<2) | (W>1 & F>0);
>> [W(ix) F(ix)]
ans =
1 0
1 2
2 2
1 0
2 3
0 3
0 0
>>
  8 Comments
Caspar Donnison
Caspar Donnison on 19 Mar 2019
Thanks - I've got there in the end, re-read all of this and started again and see how I over-complicated things. It also seems that I did nest a table in another table accidentally in the process. Thanks for helping me throughout!
dpb
dpb on 19 Mar 2019
No problem, sometimes it's difficult to step back and run back to the basics when get started down a wrong road...
If this solved the problem; be good to go ahead and "Accept" the answer to indicate so to others not take time thinking might still be open issues...

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!