Why do I get an error stating "Matrix dimensions must agree", whilst the dimensions appear to be equal to me.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dursman Mchabe
il 23 Dic 2018
Modificato: Stephen23
il 24 Dic 2018
Hi everyone,
I am runing the attached code, and for some reasons I get the error message stating:
Matrix dimensions must agree.
Error in ParametersFittingEulerMethodWater>EulerMethod (line 254)
Results = sum((Results - xdata(i,:)).^2);
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in ParametersFittingEulerMethodWater (line 58)
[b, Results] = fminsearch(@EulerMethod,b);
Whereas, to me, the dimensions appear to be equal. What am I doing wrong?
Please help.
4 Commenti
Image Analyst
il 23 Dic 2018
Modificato: Image Analyst
il 23 Dic 2018
Dursman, you have to put the size() commands into your function, not in the command window (unless you're stopped at a breakpoint), because when the function exits, the variables are gone.
I also noted that it requires the Optimization Toolbox. For some reason, you didn't fill this out, or even the release you're using, when you posted, so I'll fill in the Toolbox for you so others don't waste time trying to run your code if they don't have that toolbox.
Risposta accettata
Image Analyst
il 23 Dic 2018
When you do this:
Results - xdata(i,:)
then Results must be a column vector, not a row vector or 2-D matrix, because xdata(:, i) is a column vector. Basically : means "all", so xdata(:, i) means "All rows in column i".
Also we advise not to use i and j as variables since they also stand for the imaginary constant.
7 Commenti
Stephen23
il 24 Dic 2018
Modificato: Stephen23
il 24 Dic 2018
"I have passed b as scalar structure."
Sorry, that was my mistake: I had one thing in my mind but wrote something else: it was those global variables that I would advise to convert to a scalar structure (or use nested functions). Then you can simplify/remove all of those global calls.
Of course the function input b must be a numeric array (e.g. a vector), because that is what fminserarch will provide to your function. So leave b exactly like you had it before.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!