Search is getting failed for a library usage in Simulink model

10 次查看(过去 30 天)
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.

回答(1 个)

Harsh
Harsh 2025-1-20
编辑:Harsh 2025-1-20
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!

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by