Borrar filtros
Borrar filtros

Vector Combination - Matlab Noob

1 visualización (últimos 30 días)
Mark
Mark el 28 de Mzo. de 2013
I have two vectors that I want to merge together. Essentially I want to add them together to create another vector R3, but there is one trick. R consists of either positive or negative values or zeros. R2 consists of only 1's and zeros. In the combining, if there is a 1 in R2 in the same row as R the value should be that of R and not R2. Ex.
R =
0
0
0
-120
0
0
0
0
90
0
0
0
R2 =
1
1
0
1
0
0
0
1
0
0
0
0
Desired R3 =
1
1
0
-120
0
0
0
1
90
0
0
0
And NOT R3 =
1
1
0
-119
0
0
0
1
90
0
0
0

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 28 de Mzo. de 2013
out=R2
idx=R~=0
out(idx)=R(idx)

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by