Error: Matrix dimensions must agree

조회 수: 9 (최근 30일)
Joshua Phillips
Joshua Phillips 2015년 10월 11일
편집: Stephen23 2015년 10월 12일
Hi there,
I am having issues using the .\ operator to ldivide a matrix MxN by a vector with N rows.
Details of the Matrix:
A = 9898 x 9999
rhs = 9999 x 1
Cnew = A.\rhs
Not sure where I'm going wrong here, I've tried various combinations to see where the error is but can't seem to make it happen.
Thanks in advance

답변 (1개)

Stephen23
Stephen23 2015년 10월 11일
편집: Stephen23 2015년 10월 12일
It depends on what you are trying to do.
First you should learn about array vs. matrix operations. Knowing the difference and knowing when to use them is critical when using MATLAB!
ldivide .\ is an element-wise (or array) operator, which operates on same-sized arrays, and it divides each element of one array by the corresponding element from the other array.
mldivide \ is a matrix operation, where the number of rows of the two matrices must be the same, and it solves the linear equations defined by those matrices.
They look similar, but that period is very significant!
You have not told us if you are trying to solve linear equations, or if you are trying to simply divide all of the values. So here are both solutions. If you want to get the least-squares solution:
A\rhs % returns a least-squares solution to the system of equations A*x = rhs.
If you want to divide every element in rhs by an element of A, expanding rhs to match the dimensions of A, then try this:
bsxfun(@ldivide,A,rhs)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by