Subscripted assignment dimension mismatch.
1 次查看(过去 30 天)
显示 更早的评论
on line 330 in my code Final equation lake
0 个评论
采纳的回答
Walter Roberson
2015-10-19
G is written in terms of the complete vector N4, so the output of G will be a vector. G1 calls G so G1 is a vector. G2 calls G1 so G2 is a vector. G3 calls G2 so G3 is a vector. G4 calls G3 so G4 is a vector.
Then in your line with the problem you have
temporary(4,i) = N1(i) + (G1+2*G2+2*G3+G4)*(h/6);
but with those G1, G2, G3, G4 all being vectors, the result is a vector. And you try to store that vector in the single location temporary(4,i)
You pass particular elements of N1, N2, N3 in to G so within G those scalars shadow the vectors N1, N2, N3, but you do not pass a particular value of G4 in to G so N4 there represents the entire vector N4.
I would point out that using local parameter names the same as the name of surrounding variables is asking for exactly this kind of programming trouble where it is not apparent at a glance whether a variable name represents a particular item passed in or an entire vector. I would urge you to rewrite your series of anonymous functions to rename the parameters, making it more clear what comes from where. For example if you had written G in terms of n1, n2, n3 then if N4 appeared it would be clear it was the entire N4 and if that didn't seem appropriate and you wrote n4 but forgot to make it a parameter then you would get error messages the first time you tried to execute G because n4 would not exist at all.
Caution: in your creation of G you have a number of expressions of the form
vector / (value + vector)
Those are doing a least-squares calculation with a 1x1 result, equivalent to
vector * pinv(value + vector)
Are you sure that is what you want?
3 个评论
Walter Roberson
2015-10-19
You can comment out the creation of all of the temporary array elements, as you never use them afterwards. Once you have done that you can comment out almost everything in your "for" loop, since you turn out not to use any of the A*, B*, C* etc. variables except to calculate the temporary values that you do not use.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!