📄 clbktplt.m
字号:
function clbktplt(varargin)% Callback function template% Install this callback by invoking it with the command% clbktplt('init_block')% at the MATLAB prompt with the appropriate model file open and selected.%% To use the template, save a copy under a new name. Then replace % clbktplt with the new name everywhere it appears.action = varargin{1} ;switch action, case 'init_block', init_fcn ; % Block initialization function, % located in this M-file case 'create_fig', if(findobj('UserData',gcb)) % Don't open two for same block disp('Only open one instance per block can be opened') else % Here, put all commands needed to set up the figure and its % callbacks. left = 100 ; % Figure position values bottom = 100 ; width = 100 ; height = 100 ; h_fig = figure('Position',[left bottom width height], ... 'MenuBar','none') ; set(h_fig,'UserData',gcb) ; % Save name of current block in % the figure's UserData. This is % used to detect that a clbktplt fig % is already open for the current block, % so that only one instance of the figure % is open at a time. end case 'close_fig', % Close if open when model is closed. h_fig = findobj('UserData',gcb) ; if(h_fig) % Is the figure for current block open? close(h_fig) ; % If so, close it. end case 'rename_block', % Change the name in the figure UserData. h_fig = findobj('UserData',gcb) ; if(h_fig) % Is the figure open? set(h_fig,'UserData',gcb) ; % If so, change the name. end case 'UserAction1', % Place cases for various user actions % here. These callbacks should be defined % when the figure is created.end%************************************************************************%* init_fcn *%************************************************************************function init_fcn()% Configure the block callbacks% This function should be executed once when the block is created% to define the callbacks. After it is executed, save the model% and the callback definitions will be saved with the model. There is no need% to reinstall the callbacks when the block is copied; they are part of the% block once the model is saved.sys = gcs ;block = [sys,'/InitialBlockName'] ; % Replace InitialBlockName with the % name of the block when it is % created and initialized. This does % not need to be changed when the block % is copied, as the callbacks won't be % reinstalled.set_param(block,'OpenFcn', 'clbktplt create_fig',... 'ModelCloseFcn','clbktplt close_fig', ... 'DeleteFcn', 'clbktplt close_fig', ... 'NameChangeFcn','clbktplt rename_block') ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -