Numerical Optimization Code: ERROR Matrix Dimensions Must Agree
Mostrar comentarios más antiguos

I am trying to run a code for numerical optimization and I encountered the error message "matrix dimensions must agree". Both fitx and fitx_new were generated using a for loop. When I checked the size of x (for fitx) and the size of ui (for fitx_new), I found that they are the same. Has anyone encountered this kind of problem before? If so, what should I do? Thanks in advance!
4 comentarios
"When I checked the size of x (for fitx) and the size of ui (for fitx_new), I found that they are the same"
No you didn't check the size, because you used length.
Do NOT use length ! length is an abomination that should be ignored and not used, because the dimension that its output measures changes depending on the size of the array. Ouch!
Always use size or numel. Please show us the output of these commands:
size(fitx)
size(fitx_new)
JDL
el 1 de Ag. de 2018
Dennis
el 1 de Ag. de 2018
fitx and fitx_new have different sizes so fitx-fitx_new returns 'Matrix dimensions must agree'. You said you created both in a loop, however you didn't show the code. It is quite challenging to guess why your loop creates 2 vectors of different length without having any information about it.
JDL
el 1 de Ag. de 2018
Respuestas (0)
Categorías
Más información sobre Linear Least Squares 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!
