Only add to empty elements in an array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michael Luo
el 8 de Sept. de 2019
Comentada: Michael Luo
el 8 de Sept. de 2019
Is there a quick way to add an array to another one of equal size, BUT only add if the particular element in the first array is 0?
For example, I start with Original = zeros(3)
I want to add 3 arrays to it. lets say
a = [1 2 3; 0 0 0; 0 0 0]
b = [0 0 0; 4 5 6; 0 0 0]
c = [0 0 0; 1 1 1; 7 8 9]
If I just add a, b, and c to Original I will get [1 2 3; 5 6 7; 7 8 9] but I want the second row of c to NOT add because that row of Original already has values in it.
So it should give Original = [1 2 3; 4 5 6; 7 8 9]
I am looking to use this with 3D arrays, and preferably without for looping through each element.
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!