findRequiredToolboxes
バージョン 1.0.0 (12.8 KB) 作成者:
Hernia Baby
findRequiredToolboxes facilitates identifying the necessary toolboxes for a MATLAB script, function, or Simulink model.
This MATLAB code defines a function findRequiredToolboxes which identifies the toolboxes required for a given MATLAB script or function file. The function can handle .m, .mlx, and .slx file types. Below is a detailed explanation of the code:
function requiredToolboxes = findRequiredToolboxes(scriptPath)-
findRequiredToolboxesis the function name. -
scriptPathis the input argument, representing the file path of the MATLAB script or function. -
requiredToolboxesis the output, which will be a list of required toolboxes.
% findRequiredToolboxes - Identifies the toolboxes required for a given MATLAB script or function.
%
% Syntax: requiredToolboxes = findRequiredToolboxes(scriptPath)
%
% Inputs:
% scriptPath - The file path of the MATLAB script or function for which you want to identify required toolboxes
%
% Outputs:
% requiredToolboxes - A list of required toolboxes- This section provides a brief description of the function, its syntax, inputs, and outputs.
% You can set scriptPath with GUI or directly.
switch nargin
case 0
[file,path] = uigetfile( ...
{'*.m;*.mlx;*.slx', ...
'MATLAB Files (*.m,*.mlx,*.slx)'; ...
'*.*', 'All Files (*.*)'},'Select a file');
if isequal(file,0)
disp('User selected Cancel');
msg = 'You need to select a file.';
error(msg)
else
path = fullfile(path,file);
end
case 1
path = scriptPath;
end- This section handles the input
scriptPath. - If no input argument is provided (
nargin == 0), a file selection dialog (uigetfile) is presented to the user.- If the user cancels the file selection, an error message is displayed.
- If a file is selected, its full path is constructed.
- If an input argument is provided (
nargin == 1),pathis set toscriptPath.
% To find toolboxes
[~,~,ext] = fileparts(path);
if ext == ".slx"
sList = dependencies.toolboxDependencyAnalysis(path);
requiredToolboxes = string(sList)';
else
[~, pList] = matlab.codetools.requiredFilesAndProducts(path);
Tbox = string({pList.Name}');
Certain = cell2mat({pList.Certain}');
requiredToolboxes = Tbox(Certain);
end
end- The function then determines the file extension of the provided file using
fileparts. - If the file is a Simulink model (
.slx):-
dependencies.toolboxDependencyAnalysis(path)is used to find the required toolboxes. - The results are converted to a string array and transposed.
-
- If the file is a MATLAB script or function (
.mor.mlx):-
matlab.codetools.requiredFilesAndProducts(path)is used to find the required files and products. - The product names are extracted into a string array
Tbox. - Only the certain toolboxes (where the
Certainflag is true) are included in the final listrequiredToolboxes.
-
- The function
findRequiredToolboxesfacilitates identifying the necessary toolboxes for a MATLAB script, function, or Simulink model. - It provides flexibility by allowing the user to either input the file path directly or select it via a GUI dialog.
- It handles different file types (
.m,.mlx,.slx) appropriately to determine the required toolboxes.
引用
Hernia Baby (2025). findRequiredToolboxes (https://github.com/HerniaBaby/findRequiredToolboxes/releases/tag/V1.0.0), GitHub. に取得済み.
MATLAB リリースの互換性
作成:
R2024a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linuxタグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!| バージョン | 公開済み | リリース ノート | |
|---|---|---|---|
| 1.0.0 |
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
