Azzera filtri
Azzera filtri

Subscript indices must either be real positive???

1 visualizzazione (ultimi 30 giorni)
What does the above mean?
I have a variable that is used to count the iterations,
That same variable is matrix row specifier in another matrix.
A_matrix=[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,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,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,0,0,0,0,0]
del_hat_xi(1,1) = 0 % delta hat variables for A matrix population
del_hat_yi(1,1) = 0
del_hat_xj(1,1) = 0
del_hat_yj(1,1) = 0
del_hat_xk(1,1) = 0
del_hat_yk(1,1) = 0
coords = [1,NaN,5025.02600000000,1001.87500000000;2,NaN,5600,1500;3,NaN,5500,620;4,NaN,5100,620]
d_0_ij = [1,1,2,760.738862094609;2,2,3,885.663593019381;3,3,4,400;4,1,3,609.449601116450;5,1,4,389.165281469198]
d_0_row = 5
for r_cnt =1:d_0_row
% peruse d_0_ij FROM and TO station columns and specify A matrix
% columns to populate
del_hat_xi = d_0_ij(r_cnt,2)-1
del_hat_yi = d_0_ij(r_cnt,2)
del_hat_xj = d_0_ij(r_cnt,3)-1
del_hat_yj = d_0_ij(r_cnt,3)
% populate A matrix with values from linearised equation.
A_matrix(r_cnt,del_hat_xi) =(coords(r_cnt,d_0_ij(r_cnt,3)) - coords(r_cnt,d_0_ij(r_cnt,2))) / d_0_ij(r_cnt,4)
end
  2 Commenti
Stephen23
Stephen23 il 27 Giu 2015
Should Amatrix really be named A_matrix (or vice versa)?
Jay
Jay il 27 Giu 2015
Sorry, that was a typographical error. Should be "A_matrix" Still throws the same error with the code being rectified.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 27 Giu 2015
Modificato: Stephen23 il 27 Giu 2015
Like a lot of mathematics, MATLAB indexing starts at one. On the first loop the value of del_hat_xi is zero, which gives the error.
You can discover this yourself by setting a break-point on the line where the error occurs, and then checking the values of the indices when it stops. If you do not know how to use the debugging tools in MATLAB, now is a good time to learn how!
Although there are no doubt several ways to resolve this by making changes to this algorithm, it might actually be a good idea to tell us exactly what you desired output is, and we can show you a more efficient way of programming it.
  1 Commento
Jay
Jay il 27 Giu 2015
I see where I have gone wrong, I need an if statement to specify where to use -1 otherwise the value = 0.
Thanks.

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