Code covered by the BSD License  

Highlights from
Doraemon Helper Block

image thumbnail

Doraemon Helper Block

by

 

07 Feb 2011 (Updated )

A helper block that allow you to add blocks at ease.

addblock2model2( name,root )
function addblock2model2( name,root )
%ADDBLOCK2MODEL2 Doraemon helper block workhorse function
%   Date: Feb 7 2011

% Doraemon 
%load list
Sdoralist = load('doralist.mat','doralist');
doralist = Sdoralist.doralist;

% find entry
index = find(strcmp(doralist(:,1),name));
if index>1
    % extract info
    class = [doralist{index,3} doralist{index,4}];
    id    = doralist{index,5};
    cmd   = doralist{index,6};
    if ~isempty(class)
        load_system(doralist{index,3});
        % get original dimension
        dpos = get_param([root,'/Doraemon'],'Position');
        doffset = [dpos(3)+10 dpos(2)];

        % keep it the same size and put it beside the doraemon
        pos = get_param(class,'Position');
        pos(3:4)=pos(3:4)-pos(1:2)+doffset;
        pos(1:2)=doffset;

        % add the block
        b= add_block(class, [root,'/',id], ...
                          'MakeNameUnique', 'on' ,...
                          'Position', pos );

        % execute extra command
        eval(cmd);
    end
else
    msg=['Cannot find the short name "', name, '". Please refer to the doralist.mat file.'];
    errordlg(msg);
end

Contact us