This page extends the example discussed in the previous page and shows how to insert and append to an existing lookup table. Please download and save the associated files to the same working directory.
In the inserttable.lsf file, the following commands are used to print out the cell array that containing all the contents of the .ixml file:
clear;
tabCoupler = lookupread( "coupler_map.ixml" );
# print values
?toscript( tabCoupler );
The print out is the content in the .ixml file, which is a lookup table with one cell:
tabCoupler=cell(1);
tabCoupler{1}=struct;
tabCoupler{1}.association=cell(1);
tabCoupler{1}.association{1}=struct;
tabCoupler{1}.association{1}.design=cell(1);
tabCoupler{1}.association{1}.design{1}=struct;
tabCoupler{1}.association{1}.design{1}.name='gap';
tabCoupler{1}.association{1}.design{1}.value=3.5e-007;
tabCoupler{1}.association{1}.extracted=cell(1);
tabCoupler{1}.association{1}.extracted{1}=struct;
tabCoupler{1}.association{1}.extracted{1}.name='coupling_length';
tabCoupler{1}.association{1}.extracted{1}.value=7.18624e-006;
tabCoupler{1}.name='coupler_extracted';
Then the following script commands inserts a new cell to the existing lookup table "coupler_extracted" and prints out the cell array:
# create new association to be inserted into tabCoupler
association=struct;
association.design=cell(1);
association.design{1}=struct;
association.design{1}.name='gap';
association.design{1}.value=5e-007;
association.extracted=cell(1);
association.extracted{1}=struct;
association.extracted{1}.name='coupling_length';
association.extracted{1}.value=9e-006;
# insert association at last position
tabCoupler{1}.association = insert( tabCoupler{1}.association, association, 2 );
# print updated values
?toscript(tabCoupler);
# write into new file
lookupwrite( "coupler_map.ixml", tabCoupler );
The new cell array looks like below:
tabCoupler=cell(1);
tabCoupler{1}=struct;
tabCoupler{1}.association=cell(2);
tabCoupler{1}.association{1}=struct;
tabCoupler{1}.association{1}.design=cell(1);
tabCoupler{1}.association{1}.design{1}=struct;
tabCoupler{1}.association{1}.design{1}.name='gap';
tabCoupler{1}.association{1}.design{1}.value=3.5e-007;
tabCoupler{1}.association{1}.extracted=cell(1);
tabCoupler{1}.association{1}.extracted{1}=struct;
tabCoupler{1}.association{1}.extracted{1}.name='coupling_length';
tabCoupler{1}.association{1}.extracted{1}.value=7.18624e-006;
tabCoupler{1}.association{2}=struct;
tabCoupler{1}.association{2}.design=cell(1);
tabCoupler{1}.association{2}.design{1}=struct;
tabCoupler{1}.association{2}.design{1}.name='gap';
tabCoupler{1}.association{2}.design{1}.value=5e-007;
tabCoupler{1}.association{2}.extracted=cell(1);
tabCoupler{1}.association{2}.extracted{1}=struct;
tabCoupler{1}.association{2}.extracted{1}.name='coupling_length';
tabCoupler{1}.association{2}.extracted{1}.value=9e-006;
tabCoupler{1}.name='coupler_extracted';
Another way to add to the existing lookup table is to append to the file by using the command "lookupappend". The following scripts append a new association into this lookup table and prints out the cell array:
clear;
# create design parameter
design=cell(1);
design{1}=struct;
design{1}.name='gap';
design{1}.value=6e-007;
# create extracted parameter
extracted=cell(1);
extracted{1}=struct;
extracted{1}.name='coupling_length';
extracted{1}.value=9.9e-006;
# append to existing table
lookupappend( "coupler_map.ixml", "coupler_extracted", design, extracted );
# print contents
?toscript( lookupread( "coupler_map.ixml" ) );
And the final content in the .ixml file is listed below:
value=cell(1);
value{1}=struct;
value{1}.association=cell(3);
value{1}.association{1}=struct;
value{1}.association{1}.design=cell(1);
value{1}.association{1}.design{1}=struct;
value{1}.association{1}.design{1}.name='gap';
value{1}.association{1}.design{1}.value=3.5e-007;
value{1}.association{1}.extracted=cell(1);
value{1}.association{1}.extracted{1}=struct;
value{1}.association{1}.extracted{1}.name='coupling_length';
value{1}.association{1}.extracted{1}.value=7.18624e-006;
value{1}.association{2}=struct;
value{1}.association{2}.design=cell(1);
value{1}.association{2}.design{1}=struct;
value{1}.association{2}.design{1}.name='gap';
value{1}.association{2}.design{1}.value=5e-007;
value{1}.association{2}.extracted=cell(1);
value{1}.association{2}.extracted{1}=struct;
value{1}.association{2}.extracted{1}.name='coupling_length';
value{1}.association{2}.extracted{1}.value=9e-006;
value{1}.association{3}=struct;
value{1}.association{3}.design=cell(1);
value{1}.association{3}.design{1}=struct;
value{1}.association{3}.design{1}.name='gap';
value{1}.association{3}.design{1}.value=6e-007;
value{1}.association{3}.extracted=cell(1);
value{1}.association{3}.extracted{1}=struct;
value{1}.association{3}.extracted{1}.name='coupling_length';
value{1}.association{3}.extracted{1}.value=9.9e-006;
value{1}.name='coupler_extracted';
See also
lookupclose , lookupopen , lookupread , lookupwrite , lookupreadtable , lookupreadvalue , lookupreadnportsparameter , lookupappend , insert , Create a lookup table , List of commands