Search code examples
javamatlabimagej

Passing a variable to an ImageJ MIJI command from MATLAB


I'm trying to use the MATLAB ImageJ interface (Miji) to run a block of commands, but am having difficulty passing variables into the options for a macro command. I am attempting to load in a .tif stack of images and split them up into smaller stacks by using ImageJ's duplicate command.

From the ImageJ website for the macro builder, it states;

pass variables to commands called using run() by adding "&" variable names.

For example

values = 1-5
run("Duplicate...","duplicate range=&values")

This should duplicate an image stack within the range set by values. However when translating this to MATLABs MIJI plugin as follows;

MIJ.run('Duplicate...','duplicate range=&values')

This doesn't work and only duplicates the full image stack. Breaking the string ' ' throws an unexpected MATLAB operator error.

I have attempted storing the range values as string text as well as in a matrix.


Solution

  • I was able to do this by using sprintf

    values = 1-5;
    MIJ.run('Duplicate...',sprintf('duplicate range=%d',values));