How to apply the func change color of Input port using Set param according to naming Convention?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi Everyone,
I have a model in which more than one inputs are being used. Here inputs are of two types based on naming convention i.e. Var_In_x and Var_Par_x (x being 1,2 3 etc). I want to write a script to change the Background colour of input port i.e. Red colour for Var_In_x type naming convention and Yellow colour for Var_Par_x type of naming convention. For Example consider a model where 3 inputs are used and it aslo consist of a subsystem named "Calc" in which these inputs are being used for calculation. And I have fetched the inport data values in to a cell A using command find system:
A = find_system('Example_Model','BlockType','Inport')
Result:
A =
6×1 cell array
{'Example_Model/Var_In_1' }
{'Example_Model/Var_Par_1' }
{'Example_Model/Var_In_2' }
{'Example_Model/Calc/Var_In_1' }
{'Example_Model/Calc/Var_Par_1'}
{'Example_Model/Calc/Var_In_2' }
Now if a execute the following for loop command:
for i=1:size(A)
set_param(A{i},'BackgroundColor','red')
end
it will change the Background colour of all the input port into red.
But I only want the red colour for input port with naming convention Var_In_x type naming convention and Yellow colour with naming convention Var_Par_x. Any suggesstions ?
0 Commenti
Risposte (1)
Monika Jaskolka
il 22 Apr 2021
for i = 1:length(A)
name = get_param(A{i}, 'Name');
if regexp(name, '^Var_In_\d+$')
set_param(A{i}, 'BackgroundColor', 'red');
elseif regexp(name, '^Var_Par_\d+$')
set_param(A{i}, 'BackgroundColor', 'yellow');
end
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Programmatic Model Editing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!