KEMBAR78
Auto Create Simulink Model | PDF
0% found this document useful (0 votes)
7 views1 page

Auto Create Simulink Model

The document contains a MATLAB function named 'autoCreateModel' that demonstrates how to create a simple Simulink model. It checks for an existing model file, deletes it if found, and then constructs a new model with a sine wave, a gain block, and a scope block, connecting them appropriately. Finally, it sets model parameters and saves the created model.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Auto Create Simulink Model

The document contains a MATLAB function named 'autoCreateModel' that demonstrates how to create a simple Simulink model. It checks for an existing model file, deletes it if found, and then constructs a new model with a sine wave, a gain block, and a scope block, connecting them appropriately. Finally, it sets model parameters and saves the created model.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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);

You might also like