Want to add two 2D array with special condition

1 visualización (últimos 30 días)
ASHESH RUDRA PAUL
ASHESH RUDRA PAUL el 24 de Ag. de 2022
Editada: ASHESH RUDRA PAUL el 24 de Ag. de 2022
I want to add two 2D array and want the following result.
A=[0 0 1;1 2 3; 0 0 0 ]; B= [1 2 1; 1 0 0; 2, 3, 0].
Now I want the matrix, A+B= C=[1, 2, 1; 1,2,3; 2,3,0]
But the condition is : 0 + any number = any number; 0+0=0; sum of two number other than zero = average of two number

Respuesta aceptada

John D'Errico
John D'Errico el 24 de Ag. de 2022
Editada: John D'Errico el 24 de Ag. de 2022
Easy peasy.
A = [0 0 1;1 2 3; 0 0 0 ];
B = [1 2 1; 1 0 0; 2, 3, 0];
C = (A + B)./(1 + (A&B))
C = 3×3
1 2 1 1 2 3 2 3 0
The trick is to look carefully at what 1+(A&B) does.

Más respuestas (0)

Categorías

Más información sobre Cell Arrays 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