Creating a conditional vector

5 views (last 30 days)
Hi guys, I just have this matrix: 0010-0111-0101-1101..... and I want to create a vector with the following condition: if sum of columns 1 and 2 >=1 AND if sum of columns 3 and 4=>1 then column 5=1, otherwise column 5= 0.

Accepted Answer

Stephen23
Stephen23 on 1 Nov 2018
Edited: Stephen23 on 1 Nov 2018
Do NOT use a loop for this!
>> a = [0,0,1,0;0,1,1,1;0,1,0,1;1,1,0,1]
a =
0 0 1 0
0 1 1 1
0 1 0 1
1 1 0 1
>> a(:,5) = sum(a(:,1:2),2)>=1 & sum(a(:,3:4),2)>=1
a =
0 0 1 0 0
0 1 1 1 1
0 1 0 1 1
1 1 0 1 1

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!