Is there a 'find and replace' functionality for Simulink block parameters?
65 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 7 Mai 2018
Beantwortet: Song-Hyun Ji
am 12 Jul. 2023
I have a model with many blocks which use the same variable as the values for block parameters. Now I would like to change the variable name, but do not want to manually update each block parameter. Is there any way to find and replace all of these block parameters with the updated variable name?
Akzeptierte Antwort
MathWorks Support Team
am 19 Apr. 2023
Bearbeitet: MathWorks Support Team
am 19 Apr. 2023
Please use the documented workflow in the GUI:
https://in.mathworks.com/help/releases/R2022b/simulink/ug/workspace-variables-in-model-explorer.html
If you need a programmatic way, you can use the Simulink API to create a function doing it.
An example implementation can be found in the following:
function [replacedBlks,replacedProperties] = findReplaceParamInMdl(mdl,oldParamName,newParamName)
arguments
mdl (1,:) char {mustBeText}
oldParamName (1,:) char {mustBeText}
newParamName (1,:) char {mustBeText}
end
replacedProperties = cell.empty(0,1);
%Can be used to specify where the search needs to be done, etc.
opts = Simulink.FindOptions("FollowLinks",false);
replacedBlksH = Simulink.findBlocks(mdl,'BlockDialogParams',oldParamName,opts);
for idxBlockToReplace = 1:length(replacedBlksH)
tempBlock = replacedBlksH(idxBlockToReplace);
dlgParamsStruct = get_param(tempBlock,'DialogParameters');
dlgParams = fieldnames(dlgParamsStruct);
replacedPropertiesBlk = string.empty(0,1);
for j = 1:length(dlgParams)
if strcmp(get_param(tempBlock,dlgParams{j}),oldParamName)
set_param(tempBlock,dlgParams{j},newParamName)
replacedPropertiesBlk = [replacedPropertiesBlk; string(dlgParams{j})];
end
end
replacedProperties = [replacedProperties;{replacedPropertiesBlk}];
end
replacedBlks = getfullname(replacedBlksH);
end
0 Kommentare
Weitere Antworten (1)
Song-Hyun Ji
am 12 Jul. 2023
Since R2021a, you can use "Find and Replace Text" to replace the found text at once in Finder as in the below-captured image.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!