title: Julia: using JuMP model variable as an index
body: <p>I am writing a program in Julia that maximizes the size of an image block based on a constraint (with ** around it) as seen in the code below: </p>
  
  <pre><code>using Images, Colors, JuMP, Gurobi
  m = Model(solver=GurobiSolver(OutputFlag=0))
  Idiff=load("Idiff.png")
  a=16; b=16;
  Block=Idiff[1:a,1:b]; #initial block size
  squareBlock=sum(Block.^2) #sum of squares of block
  @variable(m,x&gt;=0,Int) #variable determining size of block in x
  @variable(m,y&gt;=0,Int) #variable determining size of block in y
  @constraint(m,x&lt;=192,Int)
  @constraint(m,y&lt;=144,Int)
  **@constraint(m,abs(sum(Idiff[1:x,1:y]).^2-squareBlock)&lt;=.1) #attempt to use 
  the variable I am optimizing as an index**
  @objective(m,Max,x+y)
  </code></pre>
  
  <p>When I try to use the variable I am optimizing as an index, I receive an error. Is there a way I could work around this issue? </p>