Borrar filtros
Borrar filtros

Creating a conditional vector

2 visualizaciones (últimos 30 días)
Andres Serrano
Andres Serrano el 1 de Nov. de 2018
Comentada: Andres Serrano el 1 de Nov. de 2018
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.

Respuesta aceptada

Stephen23
Stephen23 el 1 de Nov. de 2018
Editada: Stephen23 el 1 de Nov. de 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
  1 comentario
Andres Serrano
Andres Serrano el 1 de Nov. de 2018
thanks Stephen, it worked perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by