Download presentation
Presentation is loading. Please wait.
Published byRosamond Stokes Modified over 9 years ago
1
Simulink Model Commands April 11, 2006 http://jagger.me.berkeley.edu/~pack/e177 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. http://jagger.me.berkeley.edu/~pack/e177http://creativecommons.org/licenses/by-sa/2.0/
2
Model Construction Commands User’s typically get comfortable using the mouse to interactively alter a model –Move/Change/Delete blocks –Set parameters (in Dialog Boxes) –etc.. All of these operations have command counterparts, and can be carried out with script/function files. Some ModelConstruction Commands we will cover are –add_block, replace_block, –load_system, save_system, find_system, open_system –get_param, set_param –gbc, gcbh, bdclose, bdroot
3
System commands The main system (ie., model) helper functions are –open_system –load_system –close_system –save_system –find_system A useful command is Allblocks = find_system(ModelName)
4
Get/Set commands The get and set interface for SImulink traditionally used –get_param –set_param with blocknames as the identifier. With the list of full block names, access is easy get_param(AllBlocks{2},’ObjectParameters’) get_param(AllBlocks{2},’Name’) get_param(AllBlocks{2},’Type’) get_param(AllBlocks{2},’BlockType’) There now are also handles, and get and set work as usual H = get_param(AllBlocks{2},’Handle’) get(H,’BlockType’)
5
Model Construction Commands Diagram modification commands –add_block –replace_block
6
Model Construction Commands Current blocks, and current Model –gbc Get current block (full name) –gcbh Get current block handle –bdroot Get current model
7
Common Block Parameters There are lots of parameters common to all blocks –BackgroundColor –BlockType –ClipboardFcn, MoveFcn, InitFcn, OpenFcn, StartFcn, StopFcn, CloseFcn, DeleteFcn,... –DialogParameters, ObjectParameters –FontSize –Handle –InputSignalNames, OutputSignalNames –Parent –Selected –Type –Name –...
8
Model Parameters Each model has several(!) parameters. Some important ones are –Blocks –Dirty –CloseFcn, InitFcn, StartFcn, StopFcn –InitialState –Lock –MaxStep, MinStep, AbsTol, RelTol, Solver –ModelWorkspace –ObjectParameters –Name –SimulationStatus, SimulationTime –Tag –...
9
Mask Parameters Masked blocks have additional common parameters. –Mask –MaskCallbacks –MaskInitialization –MaskPrompts –MaskValues –MaskVariables –MaskWSVariables...
10
How could you use these Write functions that automate processing of Simulink models function exploresim1(sys) blocks = find_system(sys); for i=1:length(blocks) disp(['Name: ' get_param(blocks{i},'Name')]); disp(['Type: ' get_param(blocks{i},'Type')]); disp(' '); end
11
How could you use these function exploresim2(sys) blocks = find_system(sys); for i=1:length(blocks) disp(['Name: ' get_param(blocks{i},'Name')]); disp(['Type: ' get_param(blocks{i},'Type')]); if isequal(get_param(blocks{i},'Type'),'block') disp(['BlockType: ' get_param(blocks{i},'BlockType')]); maskstatus = get_param(blocks{i},'Mask'); if isequal(maskstatus,'on') disp(['Masked: ' 'Yes']); else disp(['Masked: ' 'No']); end disp(' '); end
12
How could you use these function exploresim3(sys) blocks = find_system(sys); for i=1:length(blocks) disp(['Name: ' get_param(blocks{i},'Name')]); disp(['Type: ' get_param(blocks{i},'Type')]); if isequal(get_param(blocks{i},'Type'),'block') disp(['BlockType: ' get_param(blocks{i},'BlockType')]); maskstatus = get_param(blocks{i},'Mask'); if isequal(maskstatus,'on') disp(['Masked: ' 'Yes']); else disp(['Masked: ' 'No']); bname = get_param(blocks{i},'Name'); startstr = ['START Fcn for Block : ' bname]; stopstr = ['STOP Fcn for Block : ' bname]; set_param(blocks{i},'StartFcn',['disp(''' startstr ''')']); set_param(blocks{i},'StopFcn',['disp(''' stopstr ''')']); end elseif isequal(get_param(blocks{i},'Type'),'block_diagram') startstr = ['MODEL START Fcn']; stopstr = ['MODEL STOP Fcn']; initstr = ['MODEL INIT Fcn']; set_param(blocks{i},'StartFcn',['disp(''' startstr ''')']); set_param(blocks{i},'StopFcn',['disp(''' stopstr ''')']); set_param(blocks{i},'InitFcn',['disp(''' initstr ''')']); end disp(' '); end
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.