How can one Loop over all Cells using num2str?

#1

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

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

matlab("
for i=1:10

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

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

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

#2

I think the following code should work:

for(i=1:10){

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!

#3

Nancy,

Thanks. That’s very helpful - as always.

Eric