Hi,
just wanted to say that I solved my problem. In fact Lucas answer gave a valuable hint. In fact I had the full path to the inport as indicated by the observation that I was able to get_param() the 'Port' parameter. However, the set_param() function apparently expects the port path as a string argument while I was using a one-dimensional cell-array returned by find_system().
Also, you must not set a Port number larger than the actual number of inports in the subsystem, because this at least screws up the display and possibly more.
All I all, this is what works for me:
function [] = ShowInPort(name, show, port)
% find block of given name in current subsystem
block = find_system(gcb, ...
'LookUnderMasks', 'on', ...
'FollowLinks', 'on', ...
'Name', name);
if isempty(block)
error('No block named "%s" found in subsystem', name);
end
if show
if strcmp(get_param(block, 'BlockType'), 'Ground')
replace_block(gcb, ...
'LookUnderMasks', 'on', ...
'FollowLinks', 'on', ...
'Name', name, 'built-in/Inport', 'noprompt');
end
% get a list of Inports
inports = find_system(gcb, ...
'LookUnderMasks', 'on', ...
'FollowLinks', 'on', ...
'BlockType', 'Inport');
% when changing the port number, be sure to never set a
% port number larger than the actual number of inports present
% in the subsystem
set_param(cell2mat(block), 'Port', num2str(min(port, length(inports))));
else
if strcmp(get_param(block, 'BlockType'), 'Inport')
replace_block(gcb, ...
'LookUnderMasks', 'on', ...
'FollowLinks', 'on', ...
'Name', name, 'built-in/Ground', 'noprompt')
end
end
Thanks anyway.