Setting batch mode in Matlab script

This might be an issue with Matlab’s bizarre (non-existent?) namespace conventions, but I cannot seem to set batch mode to “true”:

Miji(false);
>> ij.macro.Interpreter.isBatchMode()

ans =

  logical

   0

All of my attempts just overwrite the ‘ij’ object and make it a struct:

>> class(ij.macro.Interpreter.batchMode)
ans =

logical

>> ij.macro.Interpreter.batchMode = true

ij = 

  struct with fields:

    macro: [1×1 struct]

>> clear
>> ij.macro.Interpreter.batchMode = java.lang.Boolean('True')

ij = 

  struct with fields:

macro: [1×1 struct]

>> clear
>> ij.macro.Interpreter.batchMode = java.lang.Boolean(true)

ij = 

  struct with fields:

macro: [1×1 struct]

>> clear
>> ij.macro.Interpreter.batchMode = java.lang.Boolean(1)

ij = 

  struct with fields:

macro: [1×1 struct]

Does anyone know how to do this correctly?

I found the solution. In Matlab, you cannot assign static fields using the class name. Instead, you have to make an instance first:

>> inter = ij.macro.Interpreter;
>> inter.isBatchMode

ans =

  logical

   0
>> inter.batchMode = true

inter =

ij.macro.Interpreter@d2291de

>> inter.isBatchMode

ans =

  logical

   1

See Assigning to a Static Field.