MATLAB-Skript, um alle Simulink-Manual-Switch-Positionen auszugeben
Wie man die Position eines einzelnen Schalters erhält
print_manual_switch_positions.m
get_param('MySimulinkModel/Manual Switch', 'sw')Dies gibt '0' zurück, wenn der Schalter in der unteren Position ist, und '1', wenn er in der oberen Position ist.
Beispiel, wie man es ausgibt:
print_example.m
fprintf('Manual Switch: %s\n', 'MySimulinkModel/Manual Switch');Vollständiges Beispiel
Der folgende MATLAB-Befehl iteriert alle Manual-Switches im aktuell geöffneten SIMULINK-Modell rekursiv und gibt deren aktuelle Positionen im MATLAB-Befehlsfenster aus.
print_all_manual_switch_positions.m
% Find all Manual Switch blocks in the current model
current_model = bdroot;
manual_switches = find_system(current_model, 'BlockType', 'ManualSwitch');
% Output status of each Manual Switch block
for i = 1:length(manual_switches)
switch_handle = get_param(manual_switches{i}, 'Handle');
switch_pos = get_param(manual_switches{i}, 'sw');
% Display block path and status
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);
endBeispiel-Ausgabe
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)Check out similar posts by category:
Matlab/Simulink
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow