Info

此问题已关闭。 请重新打开它进行编辑或回答。

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 次查看(过去 30 天)
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.

回答(2 个)

Jan
Jan 2012-7-5
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 个评论
Archak Goel
Archak Goel 2012-7-5
hey thanks for teaching me something new. Any ways i changed my code, i made it to run in reverse order from t= 1 to 0 rather than from t = 0 to 1. Its running fine now.But I still could not get why that error was there. But as Linkin Park says.."In the end it doesn't even matter :)"
Jan
Jan 2012-7-6
编辑:Jan 2012-7-6
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.
F. 2012-7-6
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 个评论
Archak Goel
Archak Goel 2012-7-6
U r right, n is not an integer. This program or say "value of a" is valid only for n = 0.1. Otherwise a will take non integral values. I think u didn't read my description on "after running the program"
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.

Community Treasure Hunt

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

Start Hunting!

Translated by