appending to a list or an array

5 visualizaciones (últimos 30 días)
wiscoYogi
wiscoYogi el 16 de Mzo. de 2018
Editada: KSSV el 16 de Mzo. de 2018
I have three very long arrays of equal length. for each entry at a given index, I want to return the product of the three entries belonging to the three lists and put it in a new list. In other words, I want the index of the product to match the index of the three numbers multiplied to achieve it.
in python this is what I'm trying to do:
i
L1=[1,2,3]
L2=[1,2,3]
L3=[1,2,3]
L4 = []
for I in range(0,3):
L4 += L1[I]*L2[I]*L3[I]
I tried using the append([],item) function and it's not working.
would greatly appreciate help!

Respuestas (1)

KSSV
KSSV el 16 de Mzo. de 2018
Editada: KSSV el 16 de Mzo. de 2018
You need not to run a loop for this. Read about element by element operations in matlab.
L1=[1,2,3] ;
L2=[1,2,3] ;
L3=[1,2,3] ;
L4 = L1.*L2.*L3 ;

Categorías

Más información sobre Creating and Concatenating 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