Numerical Optimization Code: ERROR Matrix Dimensions Must Agree
Mostra commenti meno recenti

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 Commenti
"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
il 1 Ago 2018
Dennis
il 1 Ago 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
il 1 Ago 2018
Risposte (0)
Categorie
Scopri di più su Linear Least Squares in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
