Subscript indices must either be real positive integers or logicals
2 Ansichten (letzte 30 Tage)
Hi everybody, I wrote this code but it's seems that it has some problems. Could you help me figure out my mistakes? Thank you!
Kye Taylor am 18 Jun. 2013
Bearbeitet: Kye Taylor am 18 Jun. 2013
There are several issues you need to resolve with your code before it will run. First, there is no increment operator in MATLAB, so expressions like
need to be replaced with
k = k+1;
Once you make those changes, you'll get an error about indexing... something like
Attempted to access TRI(6,0,2); index must be a positive integer or logical.
This is because the matrix A has zeros as entries, and you're using the entries of A to index into TRI. Since I don't know your end goal, I can't suggest with much certainty how to fix that error, but the code below will run. I've added comments to every line i changed. See if it produces what you're looking for and if not, respond with the issue...
A = A + 1; % now indices are between 1 and 7 instead of 0 and 6
M=7; % changed to 7 to make TRI big enough for indices in A
TRI(A(k,m),A(k,m+1),k) = TRI(A(k,m),A(k,m+1),k) + 1; % no increment op.
m=m+1; % no increment op.
k = k+1; % no increment op.