set simulink Scope Property----BackgroundColor
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i‘m try to set simulnk Scope Property----BackgroundColor; use below code ,it works, but when close and reopen the model, the property recovered to default;

open_system([modelname '/scop4sim']);
set(0,'ShowHiddenHandles','On')
handles = guihandles(gcf);
handles.VisualizationPanel.BackgroundColor=[1 1 0];
but when set the BackgroundColor use style GUI by mouse,then close and reopen ,the BackgroundColor property is the set Vaule by mouse,not recovered;
so what’s the problem, why set by code reopen model Scope not save the property seted;
4 commentaires
Pratyush Swain
le 24 Jan 2025
Hi pangpang,
This behaviour is expected. The color changes only affect the current session and does not persist in the Simulink model. You can verify this by closing the model without saving it, for example:
set(0, 'ShowHiddenHandles', 'On');
set(gcf,'Color',[1 1 0])
% save_system('modelname');
close_system('modelname');
This will not show any error or prompt asking you to save the model and simply close the model since there is no changes associated with the model.
But alternatively, If you go through the answer to this post, if you make any changes to Scope Configuration Parameters programmatically and try to close the model before saving it will throw you an error or warning dialogue to save the model.
Lastly regarding the collor value being [ 0.9400 0.9400 0.9400], I guess it points to the right initial value.
set(0, 'ShowHiddenHandles', 'On');
get(gcf,'Color')
Before setting the color as [1 1 0], this value would also show as [0.9400 0.9400 0.9400].
Hope this helps.
Réponses (1)
Pratyush Swain
le 24 Jan 2025
Hi Pangpang,
I was able to replicate your issue successfully with a help of a sample model.
I think the issue arises because programmatically modifying the Scope block's GUI properties affects only the current session of the GUI and doesn't persist in the Simulink model. When you manually change the background color through the Scope's GUI settings, those changes are saved with the model.
We can the change the following properties of a Scope block with the help of 'Scope configuration object' as mentioned in the documentation: https://www.mathworks.com/help/simulink/ug/control-scopes-programmatically.html
For example, the title of a scope block can be changed programmatically which will persist after the model reopens as it is a part of the Scope configuration parameters:
% Open the Simulink model
modelName = 'my_model_name';
open_system(modelName);
% Give path of Scope block
scopeBlock = [modelName '/Scope'];
scopeConfig = get_param(scopeBlock, 'ScopeConfiguration');
% Change Title parameter of the Scope Configuration %
scopeConfig.Title = 'Title Changed Programmatically';
% Save the Simulink model to retain changes
save_system(modelName);
% Close the Simulink model
close_system(modelName);
Currently the Scope Configuration has around some 30 parameters which include modify the title, axis labels, and axis limits, turning on or off the legend or grid, controlling the number of inputs and displays and which display is active. It does not have any parameter related to color.
I hope this helps.
Voir également
Catégories
En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!