How to fix "matrix dimensions must agree" error
Mostrar comentarios más antiguos
I have attached my code. It gives error saying "matrix dimensions must agree". I know that something is wrong but i couldn't solve the problem. Can anyone help me with it?
Respuesta aceptada
Más respuestas (1)
Bjorn Gustavsson
el 6 de Sept. de 2022
Whe you run into problems like this you will have to learn to use the debug-capabilities of matla. Do this at the command-line:
>> dbstop in try1
This will give you the possibility to run the script line by line and inspect each variable after you've run each line at the debug-prompt. You will also be able to plot the variables, and try different combinations of transposes to see/learn which matrix dimensions should match in each operation.
We could tell you exactly what correction to make - but you learning this (tedious) procedure of investigating why how and WHY! you get different errors and unexpected behaviour will be more valuable to you even in the medium-term perspective.
HTH
1 comentario
Khadija Shah
el 7 de Sept. de 2022
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!