function that list inport names of a simulink model in matlab

main.m
function list = getSimulinkModelBlockNames(modelName)
% This function returns a list of all block names in a Simulink model
% Usage: list = getSimulinkModelBlockNames('modelName')

% Load the model
load_system(modelName);

% Get a handle to the root of the model
root = get_param(modelName,'Object');

% Get all the blocks in the model
blocks = find(root,-isa(root,'Simulink.Block'));

% Extract the block names and store in a cell array
list = cell(length(blocks),1);
for i = 1:length(blocks)
    list{i} = get(blocks(i),'Name');
end

% Unload the model
unload_system(modelName);
581 chars
22 lines

Simply run this function with the name of the Simulink model as the input argument, and it will return a cell array containing the names of all blocks in the model.

gistlibby LogSnag