-3

When I try running a code I have in MATLAB, I get the following error:

Attempted to access labels(146.864,226.509); index must be a positive
integer or logical.

Error in abc (line 11)
    l(y(i),x(i))=1;

The points are set to be chosen interactively. But, is it the points that should be an integer? I tried casting the points y(i), x(i) to int8, but didn't work. Or, maybe I'm using it wrong?

How can I solve the error above?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

1

"Integer" in this context means that they should not have any decimal fraction, it does not refer to the type.

l(round(y(i)),round(x(i))=1

should work.

In addition, you may want to check that rounding does not lead to out-of-bounds value of your array l, i.e.

y = max(min(round(y),1),size(l,1);

N.B.: l is not a particularly good name for a variable.

Jonas
  • 74,690
  • 10
  • 137
  • 177