How do I add numbers in a cell to another cell?

"R" = random number
A = {[R R X R]}
B = {[R X R X]}
How do I add the X's in cell "B" to the X in cell "A?"

7 comentarios

James Tursa
James Tursa el 1 de Mayo de 2019
Editada: James Tursa el 1 de Mayo de 2019
Please provide a small example of inputs and desired output so we know for sure what you are asking. Based on your wording, this is what you could do:
A{1}(3) = A{1}(3) + B{1}(2) + B{1}(4);
Austin Sowers
Austin Sowers el 1 de Mayo de 2019
Editada: Austin Sowers el 1 de Mayo de 2019
How would I do that, same concept, but the -10's (cells below) represent the X's from before in CA. The values to add would be, for example, the 4 and 2 in the first group of CB. I am looking for a general way to do this based on random -10 locations.
CA = {[5 -10 2],[6 6 8],[0 9 -10 8 -10 3]};
CB = {[4 17 2],[6 6 10],[9 3 4 9 7 6]};
James Tursa
James Tursa el 1 de Mayo de 2019
We are still trying to figure out the rules for your adding. What would be the desired result fot this latest example?
Austin Sowers
Austin Sowers el 1 de Mayo de 2019
Editada: Austin Sowers el 1 de Mayo de 2019
The new CA, after the adding, would be:
CA = {[5 -4 2],[6 6 8],[0 9 2 8 5 3]};
First one adding 4 and 2. Second adding 3 and 9. Third adding 9 and 6. All these values from "CB" adding to the -10 in "CA."
Austin Sowers
Austin Sowers el 2 de Mayo de 2019
Is this possible to do?
James Tursa
James Tursa el 2 de Mayo de 2019
So it appears that when you encounter a -10 in CA, you want to add the two immediate neighboring numbers from CB to it. Correct? What if the -10 is on an edge/end?
Austin Sowers
Austin Sowers el 2 de Mayo de 2019
Editada: Austin Sowers el 2 de Mayo de 2019
Good question. I will be ignoring the ones on the end for this reason.
and yes. that is correct. exactly

Iniciar sesión para comentar.

Respuestas (1)

gonzalo Mier
gonzalo Mier el 1 de Mayo de 2019
A{1}(B{1}==X) = B{1}(B{1}==X)

3 comentarios

Austin Sowers
Austin Sowers el 1 de Mayo de 2019
The X's represent the position of the random number. So all three X's could also be different numbers
Austin Sowers
Austin Sowers el 1 de Mayo de 2019
Using a numeric example:
A = {[2 3 7 1}]
B = {[1 7 9 3}]
Id want to add 7 and 3 in B to the 7 in A

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 1 de Mayo de 2019

Editada:

el 2 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by