Search code examples
matlabsimulink

Load bus definitions in function's scope


How do I use Simulink.Bus.createMATLABStruct inside a function? I'm loading some bus definitions in the function's scope but createMATLABStruct doesn't see those. If I load the bus definitions in the global workspace then the function works.

Doesn't work:

function test()
load('someBuses.mat');
s = Simulink.Bus.createMATLABStruct('aBus');
end

Works:

load('someBuses.mat');
% ...
function test()
s = Simulink.Bus.createMATLABStruct('aBus');
end

Any ideas?


Solution

  • Simulink.Bus.createMATLABStruct accepts a 4th (undocumented) input -- open the file in the editor to see the 4th input -- which can either be 'base' (the default) or a Data Dictionary object.

    The default is 'base', which is why the version you have that loads from the Base Workspace works. Have a look at this link to find out about creating Data Dictionaries.