필터 지우기
필터 지우기

Subscript indices must either be real positive???

조회 수: 1 (최근 30일)
Jay
Jay 2015년 6월 27일
댓글: Jay 2015년 6월 27일
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
Stephen23
Stephen23 2015년 6월 27일
Should Amatrix really be named A_matrix (or vice versa)?
Jay
Jay 2015년 6월 27일
Sorry, that was a typographical error. Should be "A_matrix" Still throws the same error with the code being rectified.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2015년 6월 27일
편집: Stephen23 2015년 6월 27일
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
Jay
Jay 2015년 6월 27일
I see where I have gone wrong, I need an if statement to specify where to use -1 otherwise the value = 0.
Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by