Subscripted assignment dimension mismatch.

1 visualizzazione (ultimi 30 giorni)
on line 330 in my code Final equation lake

Risposta accettata

Walter Roberson
Walter Roberson il 19 Ott 2015
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 Commenti
Walter Roberson
Walter Roberson il 19 Ott 2015
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.
KAPIL MAMTANI
KAPIL MAMTANI il 24 Ott 2015
Mr.Walter Roberson, Thank you,once again. I have rectified my storing problem. The thing you pointed out earlier, regarding creation of G is giving me problem.I tried element wise operations but that gives me NaN values. I simply want to do those operations as all operands are values. What do you suggest?

Accedi per commentare.

Più risposte (1)

Thorsten
Thorsten il 19 Ott 2015
Modificato: Thorsten il 19 Ott 2015
The variables G1, G2, G3, G4 are 1x365, so N1(i) + (G1+2*G2+2*G3+G4)*(h/6) is 1x365, and you try to assign this vector to a single element temporary(4,i)
  2 Commenti
KAPIL MAMTANI
KAPIL MAMTANI il 19 Ott 2015
Thank you for going thru my problem. I would like to say that that temporary matrix is what I tried,when I could not rectify my original code. Here is how it was... TIC{i+1} = TIC(i) + (B1+2*B2+2*B3+B4)*(h/6);
L(i+1) = L(i) + (C1+2*C2+2*C3+C4)*(h/6);
O(i+1) = O(i) + (E1+2*E2+2*E3+E4)*(h/6);
N1(i+1) = N1(i) + (G1+2*G2+2*G3+G4)*(h/6);
N2(i+1) = N2(i) + (H1+2*H2+2*H3+H4)*(h/6);
N3(i+1) = N3(i) + (I1+2*I2+2*I3+I4)*(h/6);
N4(i+1) = N4(i) + (J1+2*J2+2*J3+J4)*(h/6);
P1(i+1) = P1(i) + (K1+2*K2+2*K3+K4)*(h/6);
P2(i+1) = P2(i) + (Q1+2*Q2+2*Q3+Q4)*(h/6);
P3(i+1) = P3(i) + (R1+2*R2+2*R3+R4)*(h/6);
A(i+1) = A(i) + (T1+2*T2+2*T3+T4)*(h/6);
Z(i+1) = Z(i) + (U1+2*U2+2*U3+U4)*(h/6);
M(i+1) = M(i) + (V1+2*V2+2*V3+V4)*(h/6);
S(i+1) = S(i) + (W1+2*W2+2*W3+W4)*(h/6);
D(i+1) = D(i) + (X1+2*X2+2*X3+X4)*(h/6);
F(i+1) = F(i) + (Y1+2*Y2+2*Y3+Y4)*(h/6);
.... what do think.....thank you in advance sir.
KAPIL MAMTANI
KAPIL MAMTANI il 24 Ott 2015
problem solved....thank you

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by