How to get the exact file pathname for a linked library
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Matlab version: 2019b
Hello,
I have a Simulink 'system' model that contains several linked libraries (.slx files) from various folders. I would like to modify signal-names/data in the system model and propagate those back to the linked library files. For this, I'm using the commands
li = libinfo(bdroot);
for i = 1:length(li)
if ~strcmp(li(i).Library, 'simulink') % Ignore libraries named simulink
lib1 = sprintf("%s", string(li(i).Block)); % Get the Block name
each_lib = split(lib1, '/');
for j = length(each_lib):-1:1
this_lib = strjoin(each_lib(1:j), '/'); % Iterate to create a list of all possibilities
try
set_param(this_lib, 'LinkStatus', 'propagate') % Push the system changes to the library.
save_system(this_lib); % Save the library & close it
close_system (this_lib);
end
end
end
end
[This forced method is not bad, because the code skips over any library strings that cannot or do not need to be modified.]
This opens the corresponding linked library in a different window and pushes the changes, all good. However, the save_system gives an error indicating the library .slx file is being shadowed because another file with the same name exists in a different folder. How can I get the exact path-name for the .slx file corresponding to the linked library above so I can save the correct one? Or is there a totally better/faster way of achieving this goal?
Thanks in advance.
Joe
0 Commenti
Risposte (1)
Fangjun Jiang
il 28 Giu 2023
save_system() has options to skip prompt, ignore warning and force save.
If there are multiple files with the same name as the Simulink library file, something must be done before opening the model to make sure the library file is the correct one. Otherwise, once "propagagted", it is too late.
Once getting the libinfo(), you can use the which('libname','-all') to see all the matching files. Once confirmed that the library is correct, force save with confidence.
4 Commenti
Vedere anche
Categorie
Scopri di più su Programmatic Model Editing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!