Clear Filters
Clear Filters

Recursive directory search for all models

9 views (last 30 days)
Rohit
Rohit on 5 Jul 2023
Answered: Abhas on 5 Jul 2023
My professor and I want to test a system for all the models present in a directory. Instead of passing all the models separately by using varargin, can I somehow generate all the models in a directory as a string,so that I can split it across a .slx and get the models and test my system in one go????

Answers (1)

Abhas
Abhas on 5 Jul 2023
Hi Rohit,
Instead of writing a recursive function to get all the models of a directory, you can use a simple regex match. The line of code attached below will return a structure array with many fields, one of which is the name field. You can use the dot operator to access all the names or you can use the struct2cell function which will directly return the whole structure as cell array, which you can filter out to get the .slx models.
models=dir(fullfile(dirPath,'**/*.slx'));
You can refer this link to know more about :- https://www.mathworks.com/help/matlab/ref/regexp.html
Hope this helps!

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!