Calling for a matrix value

I need to call for values for values from teh matix Qsol every hour of the day but when i try it it gives me an error "??? Subscript indices must either be real positive integers or logicals."
t = 0:1:24
Qsol = [0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 32,71,5,5,9; 57,472,38,38,119; 83,651,68,63,286; 87,679,107,82,454; 97, 606,209,97,595; 107,457,318,107,704; 114,252,394,114,772; 116,126,420,126,795; 114,114,394,252,772; 107,107,318,457,704; 97,97,209,606,595; 87,82,107,679,454; 83,63,68,651,286; 57,38,38,472,119; 32,5,5,71,9; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0];
-Qsol(t,1)
Any help will be most appreciated :)
Thanks

 Risposta accettata

Fangjun Jiang
Fangjun Jiang il 21 Set 2011

1 voto

t can not contain 0.
Maybe t should be 1:24?
You can use this syntax to get the first column of Qsol
Qsol(:,1)

5 Commenti

Hussein
Hussein il 21 Set 2011
Thanks a lot :)
Hussein
Hussein il 21 Set 2011
I got another question, I am building a program that solves 22 equations for each hour of the day, and each hour of the day some values change in the equations until now i have come to this,
Tomax = 37;
Tomin = 25;
hi = 4.25;
ho = 2.85;
hr = 1.5;
Ks = 0.72;
Kc = 1;
Kg = 0.72;
Xs = 0.0015;
Xc = 0.2;
Xg = 0.003;
Cs = Ks/Xs;
Cc = Kc/Xc;
Cg = Kg/Xg;
Cp = 1;
Kair = 0.0257;
Dair = 1.2;
Ar = 80;
An = 20;
As = 20;
Aw = 25;
Ae = 25;
Af = 80;
Ws = 3;
Ww = 1.5;
We = 1.5;
ACH = 0.5;
V = 200;
t = 1:24
Qgen = [140,140,140,140,140,140,140,140,2140,70,70,70,70,70,70,70,70,70,140,2140,140,140,140,140];
To = (Tomax+Tomin)/2 + (Tomax-Tomin)/2*sin(3.14/12*(t-9));
Tsky = To - 5;
Qsol = [0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 0,0,0,0,0; 32,71,5,5,9;
57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0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,Cg,-Cg-hi,0,0,0,0,hi,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-hr-ho-Cc,Cc,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Cc,-Cc-Cg,Cg,0,0,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Cg,-Cg-hi,0,hi,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-Af*(hi+hr),Af*(hi+hr),0;
0,0,0,hi,0,0,0,hi,0,0,0,hi,0,0,0,hi,0,0,hi,hi,-6*hi,0;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,ACH*V*Dair*Cp,1]
Cons = [-Qsol(t,1) - Tsky*hr - To*ho;0;0;0;
-Qsol(t,2) - Tsky*hr - To*ho;0;0;0;
-Qsol(t,3) - Tsky*hr - To*ho;0;0;0;
-Qsol(t,4) - Tsky*hr - To*ho;0;0;0;
-Qsol(t,5) - Tsky*hr - To*ho;0;0;
-Ws*Qsol(t,3) - We*Qsol(t,2) - Ww*Qsol(t,4);
-Qgen(t) - Qinf;
ACH*V*Dair*Cp*To]
When i run it it gives me Error using ==> minus
Matrix dimensions must agree.
Can you help me ?
Thanks
Fangjun Jiang
Fangjun Jiang il 21 Set 2011
In the last statement, Qsol(t,1) is a 24 by 1 vector, but Tsky*hr is a 1 by 24 vector. That causes the problem. If you save the above code in a script and run it, it will tell you which line cause the problem. Also, you can set a break point and run the code line by line. In the M-editor, click menu Debug.
Hussein
Hussein il 21 Set 2011
Thanks :) I am going to try it right away and how do i switch the Qsol(t,1) from 24 by 1 to 1 by 24
Thanks :)
Fangjun Jiang
Fangjun Jiang il 21 Set 2011
Use function transpose(), in many case, use the single quote symbol,'
A=1:5; B=A';

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by