12 views (last 30 days)

i am getting this error

Array indices must be positive integers or logical values.

Error in tabular/dotParenReference (line 108)

b = b(rowIndices);

Error in tryout (line 12)

z1 = sum(y.resource (p:T).^2)

for the following lie of code

z1 = sum(y.resource (p:T).^2)

here i would be taking values from variable resource in table y, for which sum till end day of project(t) whose square is found.

i hope this explains the above line from code.

John D'Errico
on 14 Oct 2019

Edited: John D'Errico
on 14 Oct 2019

p is sometimes zero. sometimes it is one. how you are creating p is a bit silly, as there is absolutely no reason to use bin2dec, and num2str is also a bit over the top. For example, I tried it twice, and I see:

>> x1 = round(rand() );

p = bin2dec(num2str(x1))

p =

1

>> x1 = round(rand() );

p = bin2dec(num2str(x1))

p =

0

But then you have the line:

z1 = sum(y.resource (p:T).^2)

if sometimes p is zero, then you create a vector p:T. Whenever p is zero, then p:T will be a vector that STARTS at zero.

When p is zero, can you use that vector as an index into the variable y.resource?

NO.

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

Start Hunting!
## 2 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/485127-array-indices-must-be-positive-integers-or-logical-values#comment_755894

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/485127-array-indices-must-be-positive-integers-or-logical-values#comment_755894

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/485127-array-indices-must-be-positive-integers-or-logical-values#comment_755921

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/485127-array-indices-must-be-positive-integers-or-logical-values#comment_755921

Sign in to comment.