Borrar filtros
Borrar filtros

How can I fix the error when multiple two matrices?

3 visualizaciones (últimos 30 días)
Nguyen Tuan
Nguyen Tuan el 6 de Ag. de 2015
Respondida: Steven Lord el 6 de Ag. de 2015
I have two (100*1) matrices. When I multiple them, an error occured "??? Error using ==> mtimes Inner matrix dimensions must agree. Please help me to fix it

Respuesta aceptada

James Tursa
James Tursa el 6 de Ag. de 2015
Did you mean element-wise multiplication? If so, use the .* operator. E.g.,
a = your 100 x 1 vector
b = your 100 x 1 vector
result = a .* b;

Más respuestas (1)

Steven Lord
Steven Lord el 6 de Ag. de 2015
How do you want to multiply them? Element-by-element, to generate a vector the same size as x and y where each element is the product of the corresponding elements in x and y?
x = (1:10).';
y = (1:10).';
z1 = x.*y; % NOTE the period
isequal(z1(4), x(4)*y(4)) % for scalar multiplication, the * and .* operators are the same
Do you want to generate a 1-by-1, the dot product of the two vectors?
z2 = dot(x, y);
z3 = x.'*y;
isequal(z2, sum(x.*y))
isequal(z2, z3)
Do you want to generate a 10-by-10 matrix, the multiplication table for x and y?
z4 = x*y.';
isequal(z4(7, 8), x(7)*y(8))
multiplicationTable = [NaN, y.'; x, z4]

Categorías

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