Borrar filtros
Borrar filtros

Join elements of an array

1 visualización (últimos 30 días)
fede
fede el 12 de Jul. de 2015
Comentada: Image Analyst el 12 de Jul. de 2015
If I have two array
a=[1 2 3 0]
b=[0 0 5 4]
and I want the array c=[1 2 3 4] How should I proceed?
In other words I want a array c in which the element of array a==0 is replaced with the element of matrix b.
  1 comentario
Image Analyst
Image Analyst el 12 de Jul. de 2015
What happened to the 5? Why did you leave that out of c?

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Jul. de 2015
Editada: Azzi Abdelmalek el 12 de Jul. de 2015
a=[1 2 3 0]
b=[0 0 5 4]
idx=a==0
bb=sort(nonzeros(b))
a(idx)=bb(1:sum(idx))
  2 comentarios
fede
fede el 12 de Jul. de 2015
Editada: Azzi Abdelmalek el 12 de Jul. de 2015
mmmm but if i want a general formula? I have two arrays of prices.
a=[p1 p2 p3 0 0 0 ....]
b=[0 0 p3 p4 p5 0 0....]
and I want join the two arrays to obtain a array c in which I have
c=[p1 p2 p3 p4 p5]
Azzi Abdelmalek
Azzi Abdelmalek el 12 de Jul. de 2015
Have you tried my code?

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by