Subscripted assignment dimension mismatch.
1 次查看(过去 30 天)
显示 更早的评论
Basic background: Solving optimization problem looking for minimum of Rosenbrock function. Function flinesearch returns the alphamin, fmin, and number of iterations taken (k). Attempting to put these results in a simple matrix to view including the alphastart value. Code is shown below.
for i=1:51 % 50 iters
alphastart = i*0.1;
[alphamin,fmin,k] = flinesearch(z,dz,x,s,alphastart,fminbound);
r(i,:) = [alphastart, alphamin, fmin, k];
end
fprintf('AlphaStart - AlphaMin - fMin - Iters \r\n')
r
The code tags the error "Subscripted assignment dimension mismatch." on r(i,:) = [alphastart, alphamin, fmin, k];
The frustration occurs because when the code did not include the iterations to be included in the matrix, it would generate and display the matrix perfectly fine, ie.
r(i,:) = [alphastart, alphamin, fmin];
Confused as to why once the 'k' value is to be added into each row, it does not function anymore.
Any help is appreciated, thanks.
2 个评论
Bob Thompson
2019-2-25
Did you clear the previous version of 'r'? You already had 'r' defined as a three column array, but if you don't clear it then when you add the 'k' to row it will attempt to add a fourth element to one row of an array which has three columns elsewhere.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!