How can I divide each element of a vector by each of the elements of another vector in MATLAB?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eilidh Kaune
el 8 de Abr. de 2021
Comentada: dpb
el 8 de Abr. de 2021
Say I have two vectors:
a= [ 1
2
3 ];
b=[4
5
6];
And I want
c= [1/4
2/4
3/4
1/5
2/5
3/5
1/6
2/6
3/6];
Is there a way to do this?
1 comentario
dpb
el 8 de Abr. de 2021
I'm undoubtedy overlooking the obvious but
cell2mat(arrayfun(@(i)a/b(i),1:numel(b),'UniformOutput',false))
Respuesta aceptada
James Tursa
el 8 de Abr. de 2021
Editada: James Tursa
el 8 de Abr. de 2021
Assuming a and b are both column vectors, you can use automatic array expansion by transposing one of them and using element-wise divide:
c = a ./ b.'; % results in a 2D matrix
c = c(:); % turn 2D matrix into a column vector
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!