i need a documentation about creating a Simulink simulation file from Matlab code
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I want a book or PDF or other documentation apropos to create a Simulink simulation file from Matlab code
as below
% Paramètres
Ts = 0.0005; % Temps d'échantillonnage
num_outputs = 41; % Nombre de sorties
modelName = 'GeneratedModelWithScope';
% Vérifiez si le modèle existe déjà et, le cas échéant, supprimez-le
if bdIsLoaded(modelName)
close_system(modelName, 0);
bdclose(modelName);
end
% Création d'un nouveau modèle Simulink
new_system(modelName);
open_system(modelName);
% Ajout du bloc de signal aléatoire
add_block('simulink/Sources/Random Number', [modelName '/Random Signal'], 'Position', [20, 20, 70, 50]);
set_param([modelName '/Random Signal'], 'SampleTime', num2str(Ts));
% Ajout des blocs Delay et reliure à la source
for i = 1:num_outputs
delay_name = [modelName '/Delay' num2str(i)];
add_block('simulink/Discrete/Delay', delay_name, 'Position', [100*i, 50, (100*i+ 50), 50+30]);
end
for i = 1:num_outputs
delay_name = [modelName '/Delay' num2str(i)];
set_param(delay_name, 'SampleTime', num2str(Ts));
set_param(delay_name,'Delay', i);
add_line(modelName, 'Random Signal/1', ['Delay' num2str(i) '/1']);
end
% Ajout du bloc multiplexeur
mux_pos = [200, 20, 250, 20 + num_outputs*50];
mux_name = [modelName '/Mux'];
add_block('simulink/Signal Routing/Mux', mux_name, 'Position', mux_pos);
set_param(mux_name, 'Inputs', num2str(num_outputs));
% Reliure des sorties Delay au multiplexeur
for i = 1:num_outputs
add_line(modelName, ['Delay' num2str(i) '/1'], ['Mux/', num2str(i)]);
end
% Ajout du bloc oscilloscope
scope_pos = [300, (num_outputs*50)/2 - 40, 370, (num_outputs*50)/2 + 40];
scope_name = [modelName '/Scope'];
add_block('simulink/Sinks/Scope', scope_name, 'Position', scope_pos);
set_param(scope_name, 'NumInputPorts', '41');
% Reliure du multiplexeur à l'oscilloscope
add_line(modelName, 'Mux/1', 'Scope/1');
% Ajustement de la vue pour voir tous les blocs
Simulink.BlockDiagram.arrangeSystem(modelName);
0 Commenti
Risposte (1)
Steven Lord
il 13 Ago 2023
You mean programmatic creation and editing of a Simulink model? See this section of the documentation.
0 Commenti
Vedere anche
Categorie
Scopri di più su General Applications in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!