How can one Loop over all Cells using num2str?

Is there a way to loop over all cells to get mode field data?

For example, something like this (which doesn’t work) - Thanks:

for i=1:10

str = [’ "::model::EME::Cells::cell_’ num2str(i) ’ " ']

data = getresult( str, “mode fields” );

matlabsave("[‘unit’ num2str(i) ‘.mat’]", data);

I think the following code should work:


str = "::model::EME::Cells::cell_"+num2str(i);

data = getresult( str, "mode fields" );

matlabsave("unit"+num2str(i)+'.mat', data);

Saving data to a .mat file doesn’t require opening Matlab at all, so in the above code, I’ve removed the “matlab” script command which sends commands to Matlab to run, and I’ve converted the syntax of the commands to the Lumerical scripting language syntax.

Let me know if you have any questions about it!

1 Like


Thanks. That’s very helpful - as always.