Incorrect dimensions for matrix multiplication.

Z=[cos(x)*cos(sqrt(X.^2 + Y.^2))]*e.^-mod(2*x) ;
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in main (line 9)
Z=[cos(x)*cos(sqrt(X.^2 + Y.^2))]*e.^-mod(2*x) ;

回答 (1 件)

Aashray
Aashray 2025 年 2 月 8 日

0 投票

The error indicates that the dimensions of the matrices are not consistent with respect to matrix multiplication. For more information regarding the “dimension of matrix,” refer to the MATLAB documentation:
Assuming that “X” and “Y” are matrices of size “m x n”, then the size of the matrix “x” must be “n x m” in order to satisfy compatibility.
X = zeros([m,n]);
Y = ones([m,n]);
x = ones([n,m]);
e = exp(1);
Z = [cos(x)*cos(sqrt(X.^2 + Y.^2))]*e.^-abs(2*x);

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 11 月 21 日

回答済み:

2025 年 2 月 8 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by