12/06/25 11:17 /Users/dr.dsp/Research.../autoCreateModel.
m 1 of 1
function autoCreateModel
% function to demonstrate how to create a simple Simulink model
% Author: Dr. DSP ASSALA (assala_pascal@yahoo.fr)
% Specify the name of the model to create
fname = 'autoCreatedModel';
% Check if the file already exists and delete it if it does
if exist(fname,'file') == 4
% If it does then check whether it's open
if bdIsLoaded(fname)
% If it is then close it (without saving!)
close_system(fname,0)
end
% delete the file
delete([fname,'.mdl']);
end
% Create the system
new_system(fname);
% Add a Sine Wave, making the sample time continuous
add_block('built-in/Sin', [gcs,'/Sine Wave'],...
'Position', [140 95 170 125],...
'SampleTime','0');
% Add a gain block, setting the gain value to 2
add_block('built-in/Gain', [gcs,'/Gain'],...
'Position',[240 95 270 125],...
'Gain','2');
% Add a scope block
add_block('built-in/Scope', [gcs,'/Scope'],...
'Position',[350 94 380 126]);
% Connect the sine and the gain
add_line(gcs,'Sine Wave/1','Gain/1')
% Connect the gain and the scope
add_line(gcs,'Gain/1','Scope/1')
% Set a couple of model parameters to eliminate warning messages
set_param(gcs,...
'Solver','FixedStepDiscrete',...
'FixedStep','0.1');
% Save the model
save_system(fname);