Search is getting failed for a library usage in Simulink model

17 views (last 30 days)
I wanted to search number of instances of a library being used in the entire simulink model and also wanted to know all the path where the library is being is used.
But it is not working and says "Search Failed"
I have already increased "Java Heap Memory" to MAX in preferences.
Also deleted all temp files from temp folder and restarted PC and Matlab but still problem exists.

Answers (1)

Harsh
Harsh on 20 Jan 2025
Edited: Harsh on 20 Jan 2025
As a workaround, you can try programmatically searching for the number of instances of a library by following the example mentioned below:
% Loads the Simulink model named 'example.slx'
expLib = load_system('example.slx');
% Find all blocks within the loaded system, including those under masks
expLibBlocks = find_system(expLib, 'LookUnderMasks', 'all', 'Type', 'Block');
% Retrieve the block types of all found blocks and store them in an array
blockTypeArray = get(expLibBlocks, 'BlockType');
To count the number of occurances, you can use the following function. Please note that if you're using a custom library block, this function will not be able to count the occurrences of its subsystem.
function count = countStringOccurrences(cellArray, searchString)
% countStringOccurrences counts the occurrences of a string in a cell array.
% Initialize the count to zero
count = 0;
% Loop through each element in the cell array
for i = 1:length(cellArray)
% Check if the current element is a string and matches the search string
if ischar(cellArray{i}) && strcmp(cellArray{i}, searchString)
% Increment the count if a match is found
count = count + 1;
end
end
end
Here's an example of the "countStringOccurrences" function being used.
numOfOccurences = countStringOccurrences(blockTypeArray, 'Outport')
To programmatically find the path of a library block in a model, you can use the following code snippet:
pathOfTheBlock = get(find_system(ex, 'Name', 'Outport')).Path
I hope this helped, thanks!

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!