I am using MATLAB 2013b, and I am attempting to write a script that will automatically wire up ToWorkspace blocks to a selected set of signals.
I can handle finding/getting handles to the signals, adding the blocks, setting the variable names, and so forth. What I want to do, however, is programmatically discover if a selected signal is a scalar, array, or bus signal. This way, I can reshape arrays to be 1D (so that they concatenate the way I want) and break down bus signals into their individual elements.
I attempted the fix posted at See if a signal originates from a bus in Simulink but with no luck. I'm betting that the post is old enough that the proposed fix didn't work in the version of MATLAB I'm attempting to use.
I know the answer involves compiling the model or updating the model with a certain command, but I am stuck. Help please!
Here's what I tried to do, based on the link above:
function usedNames = addToWorkspaceBlock( signal, usedNames )
% Recursively add whatever blocks are necessary to break down the signal
% into raw bus elements or reshaped arrays and output them that way
switch upper( get(signal,'CompiledBusType') )
case 'NOT_BUS'
% Will add the reshape block and ToWorkspace block here, saving
% the name of the ToWorkspace VariableName to usedNames
keyboard % for debugging
case {'VIRTUAL_BUS','NON_VIRTUAL_BUS'}
% Will add the reshape block and ToWorkspace block here, saving
% the name of the ToWorkspace VariableName to usedNames
keyboard % for debugging
otherwise
error('Unrecognized CompiledBusType %s', get(signal,'CompiledBusType'));
end
end
The error I get is this: (ignore the line numbers; my addToWorkspaceBlock()
function is a subfunction of my main function which handles getting the signals and looping through them)
Error using createToWorkspaceBlocks>addToWorkspaceBlock (line 48)
line does not have a parameter named 'CompiledBusType'
Error in createToWorkspaceBlocks (line 36)
usedNames = addToWorkspaceBlock( signals(i), usedNames );