How to apply the func change color of Input port using Set param according to naming Convention?
7 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Monika Jaskolka
on 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 Comments
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!