how to multiply each element of a cell array by a different scalar

29 visualizaciones (últimos 30 días)
I have a cell array V={[1 2 3;4 5 6],[0 0 0;1 2 9],[0 9 3;2 4 6]} and a vector a=[2 3 4]. I want to multiply the first cell elements of V by the first element of a, i.e., [1 2 3;4 5 6] 2 , the second cell elements of V by the second element of a, i.e., [0 0 0;1 2 9]3, etc. How can I do that?.

Respuesta aceptada

Guillaume
Guillaume el 14 de Ag. de 2019
The easiest would be:
result = cellfun(@times, V, num2cell(a), 'UniformOutput', false)
or just use a loop.
Note that V and a must have the same size:
assert(isequal(size(V), size(a)), 'sizes not equal')

Más respuestas (0)

Categorías

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