Script MATLAB pour imprimer toutes les positions des commutateurs manuels Simulink
Comment obtenir la position d’un seul commutateur
print_manual_switch_positions.m
get_param('MySimulinkModel/Manual Switch', 'sw')Ceci retournera '0' si le commutateur est en position inférieure et '1' s’il est en position supérieure.
Exemple comment l’imprimer :
print_example.m
fprintf('Manual Switch: %s\n', 'MySimulinkModel/Manual Switch');Exemple complet
La commande MATLAB suivante itérera tous les commutateurs manuels dans le modèle SIMULINK actuellement ouvert récursivement et imprimera leurs positions actuelles dans la fenêtre de commande MATLAB.
print_all_manual_switch_positions.m
% Trouver tous les blocs Manual Switch dans le modèle courant
current_model = bdroot;
manual_switches = find_system(current_model, 'BlockType', 'ManualSwitch');
% Afficher le statut de chaque bloc Manual Switch
for i = 1:length(manual_switches)
switch_handle = get_param(manual_switches{i}, 'Handle');
switch_pos = get_param(manual_switches{i}, 'sw');
% Afficher le chemin du bloc et le statut
if strcmp(switch_pos, '0')
position = 'Lower Position';
else
position = 'Upper Position';
end
fprintf('Manual Switch: %s\n', manual_switches{i});
fprintf('Status: %s (%s)\n\n', switch_pos, position);
endExemple de sortie
manual_switch_print_output.txt
Manual Switch: MySimulinkModel/Manual Switch
Status: 0 (Lower Position)
Manual Switch: MySimulinkModel/Subsystem/My second switch
Status: 1 (Upper Position)Consultez les articles similaires par catégorie :
Matlab/Simulink
Si cet article vous a aidé, pensez à m'offrir un café ou à faire un don via PayPal pour soutenir la recherche et la publication de nouveaux articles sur TechOverflow