Search is getting failed for a library usage in Simulink model

조회 수: 4 (최근 30일)
Balaji V
Balaji V 2025년 1월 17일
댓글: Balaji V 2025년 1월 20일
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