Multiple one column of one matrix with all column of another matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yen Su
el 1 de Feb. de 2021
Comentada: Yen Su
el 1 de Feb. de 2021
I have two array
array1=[0.5 0.7 0.9; 1.2 1.8 2.1;2.5 3.4 5.3; 3.1 7.1 2; 3 4 8; 9 4 7; 1 2 3; 4 3 9]
and
array2=[21 23 24 27; 21 87 45 33; 55 88 66 44; 33 21 34 55; 33 87 43 98;21 23 24 27;21 23 24 27;21 23 24 27]
I want to multiply each data of second column of array1 i.e (0.7 1.8 3.4 7.1 4 4 2 3) with all element of array2 column to column (i.e. 0.7x21 1.8x21 3.4x55 7.1x33 4x33 4x21 2x21 3x21 and so on). How can I do that? Any advice is appreciated.
0 comentarios
Respuesta aceptada
the cyclist
el 1 de Feb. de 2021
Editada: the cyclist
el 1 de Feb. de 2021
If you have a relatively up-to-date version of MATLAB (R2016b or later), with implicit expansion, then
output = array1(:,2).*array2;
will give the result you want.
If you have an older version, you'll need to do the expansion yourself, for example with
output = repmat(array1(:,2),1,size(array2,2)) .* array2;
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping 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!