Divide each element of an array by the corresponding element of another array

28 visualizaciones (últimos 30 días)
I have 2 cell arrays of numbers, e.g.:
a = [1, 2, 3]
b = [4, 5, 6]
and I want to divide each element of a by the corresponding element of b (1/4, 2/5, and 3/6). In python I used the 'zip' function to achieve this, but I'm not sure if anything similar exists in Matlab. Here is what I have done so far but this is not working:
for num = a
newnum = cell2mat(num);
output = newnum / b(num);
outputs(end+1) = output;
end
Thanks for the help guys, I'm brand new to Matlab so apologies for the code!
  2 comentarios
dpb
dpb el 29 de Jul. de 2021
c=a./b;
Read the "Getting Started" to get basic syntax...
Jan
Jan el 29 de Jul. de 2021
Editada: Jan el 29 de Jul. de 2021
Ouch - for the code :-)
See https://www.mathworks.com/learn/tutorials/matlab-onramp.html for a tutorial for the Matlab basics in addition to dpb's suggestion.
@dpb: Please post this as answer, because it solves the problem.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 29 de Jul. de 2021
c=a./b;
Read the "Getting Started" to get basic syntax...

Categorías

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