what’s the difference between .* and * in matlab

In MATLAB, .* is the element-wise multiplication operator, while * is the matrix multiplication operator.

For example, consider two matrices A and B:

main.m
A = [1 2; 3 4];
B = [5 6; 7 8];
32 chars
3 lines

Using .*:

main.m
C = A .* B;
12 chars
2 lines

This would result in element-wise multiplication:

main.m
C = [5 12; 21 32];
19 chars
2 lines

Using *:

main.m
D = A * B;
11 chars
2 lines

This would result in matrix multiplication:

main.m
D = [19 22; 43 50];
20 chars
2 lines

related categories

gistlibby LogSnag