Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
This error- "index must be a positive integer or logical. " is occuring inspite of the fact that i have checked my program for all possible errors. Please help
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Program -
Px = zeros(11,11);
Py = zeros(11,11);
Pz = zeros(11,11);
t = 1;
a = 1+(10*t);
while(t<=1)
u = 0:n:t;
w = t:-n:0;
v = 1-(u+w);
col = 1;
while(col<=(a))
V = v(1,col);
U = u(1,col);
W = w(1,col);
Px(a,col) = P00(1,1)*W + P10(1,1)*U + P11(1,1)*V -(C(1,1)*W*U)-(C(1,2)*U*V)-(C(1,3)*W*V);
Py(a,col) = P00(2,1)*W + P10(2,1)*U + P11(2,1)*V -(C(2,1)*W*U)-(C(2,2)*U*V)-(C(2,3)*W*V);
Pz(a,col) = P00(3,1)*W + P10(3,1)*U + P11(3,1)*V -(C(3,1)*W*U)-(C(3,2)*U*V)-(C(3,3)*W*V);
col = col+1;
end
t = t-n
a = 1+(10*t);
end
grid on;
Error in ==> qpatch1 at 139
Px(a,col) = P00(1,1)*W + P10(1,1)*U + P11(1,1)*V -(C(1,1)*W*U)-(C(1,2)*U*V)-(C(1,3)*W*V);
**input to be given* - *
enter all values in [a b c] format
enter the first point[0 0 0]
enter the second point[1 1 0]
enter the third point[2 0 0]
enter the first normal[-1 0 0.4]
enter the second normal[-0.5 0.5 0.3]
enter the third normal[0.6 -0.6 0.3]
enter the resolution0.1
enter the allowed smallest value of delta C0.001
After running the program-
if i will write in command window Px(7,1) it will give answer. If i will write a, it will give as 7. and col as 1. now if i write Px(a,1) or Px(a,col) then it wil give this error. this is the silliest of errors i have ever seen!! if u define a new matrix in command window(11 cross 11) and then try to access any of its values using the same a as variable, u wil again get the same error.
0 commentaires
Réponses (2)
Jan
le 5 Juil 2012
What is P00. P10 and P11 is? If these are matrices, the only wrong index in this line can be "a" or "col". So type:
dbstop if error
Start your program and Matlab stops, when the error occurs. Then type in the command window:
a
col
P00(1,1)*W + P10(1,1)*U + P11(1,1)*V-(C(1,1)*W*U)-(C(1,2)*U*V)-(C(1,3)*W*V)
Px(a,col)
What do you see?
This procedure is called "debugging" and it is even more powerful than this forum.
2 commentaires
Jan
le 6 Juil 2012
Modifié(e) : Jan
le 6 Juil 2012
You have described your problem. I took the time to provide a method to investigate the cause of the problem and asked you to post the value of the variables. You answered, that you have changed the code.
Well, when you do not answer my questions for clarifications, I cannot assist you to solve your problem.
F.
le 6 Juil 2012
Could you explain what is n ??
t=1 and u=0:n:t so n<1 and n is not an integer (I think)
After the first loop, t=t-n and a=1+(10*t), are you sure that "a" is an integer ?
No , and it’s a problem for Px(a,col).
Try to cast “a” as an integer
2 commentaires
F.
le 6 Juil 2012
What did you do ?
1) a = 7; col = 1 ; P( a, col )
2) n = 0.4 ; t = 1 - n ; a = 1 + ( 10 * t ) ; P( a, col )
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!