Why do I get the error message 'Inner matrix dimensions must agree. ' ?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Feb. 2012
Kommentiert: Walter Roberson
am 19 Apr. 2022
Why do I get the following error message :
ERROR: Inner matrix dimensions must agree.
Akzeptierte Antwort
MathWorks Support Team
am 12 Okt. 2021
Bearbeitet: MathWorks Support Team
am 17 Nov. 2021
Explanation:
You are attempting to perform a matrix operation, which requires certain matrix dimensions to agree, on matrices that do not satisfy this requirement.
Common causes:
You are attempting to multiply or divide two matrices where the number of columns in the first is not equal to the number of rows in the second (for *) or the number of rows do not match (for \). This often indicates that you are performing matrix operations when you instead intended to perform array operations.
Please refer to the attached example demonstrating this error:
MatrixDimensionsMustAgree.m
Solution:
Stop MATLAB on the line where the error occurs. Verify that you are not performing an extra transpose operation or omitting one where necessary. Also verify the sizes of the matrices, which you are multiplying or dividing, agree in the corresponding dimensions. You can do this using the Workspace browser or the SIZE function. If you intended to perform array operations instead of matrix operations, replace the *, /, \, or ^ matrix operators with the .*, ./, .\, or .^ array operators instead. If you pass your formula as a string to the VECTORIZE function, VECTORIZE will return the formula with the matrix operators (*, /, and ^) replaced by the array operators (.*, ./, .^).
https://www.mathworks.com/help/matlab/ref/vectorize.html
2 Kommentare
Walter Roberson
am 19 Apr. 2022
That is missing too much code for us to give much in the way of assistance. We have no idea what the sizes are for all those variables. Also, you did not indicate which MATLAB release you are using.
My pure guess is that your code has a / where it should have a ./ so you are getting a variable with a size you do not expect.
Weitere Antworten (1)
Greg Heath
am 28 Apr. 2016
For N I-dimensional inputs paired with N O-dimensional target outputs
[ I N ] = size(input)
[ O N ] = size(target)
I always place these right after I read the data in.
Hope this help.
Thank you for formally accepting my answer
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!