プログラムによるプロジェクトの作成と参照
R2026bこの例では、プログラムで新しいプロジェクトを作成し、それを参照プロジェクトとしてメインのプロジェクトに追加する方法を説明します。コマンド ラインからのプロジェクトの作成、ファイルとフォルダーの追加、プロジェクト パスの設定、プロジェクトのショートカットの定義、および別プロジェクトの新しいプロジェクトへの参照の作成方法を説明します。
例のファイルの設定
機体のプロジェクトを開きます。currentProject を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。
openExample("simulink/AirframeProjectWithOneReferencedProjectExample")
mainProject = currentProjectmainProject =
Project with properties:
Details
Name: "Airframe Example"
Summary: "This example project demonstrates the Project referencing feature."
RootFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/airRef"
DefinitionFilesType: FixedPathMultiFile
TopLevel: 1
Files
Files: [1×22 matlab.project.ProjectFile]
Shortcuts: [1×2 matlab.project.Shortcut]
Categories: [1×1 matlab.project.Category]
Dependencies: [1×1 digraph]
DependencyCacheFile: ""
Environment
ProjectStartupFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/airRef"
StartupFiles: [1×0 string]
ShutdownFiles: [1×0 string]
PathFolders: [4×1 string]
TestFolders: [0×1 string]
ProjectDependencies: [1×1 matlab.project.Dependency]
ProjectReferences: [1×1 matlab.project.ProjectReference]
Simulink
StartSimulink: 1
RefreshSimulinkCustomizations: 0
SimulinkCacheFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/airRef/work/cache"
SimulinkCodeGenFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/airRef/work/codegen"
Airframe Example プロジェクトは、参照プロジェクト (ProjectReferences: [1x1]) を 1 つもつ最上位レベル プロジェクト (TopLevel: 1) です。
新規プロジェクトの作成
Wind Gust Library と呼ばれる新規プロジェクトを作成します。Airframe プロジェクトはプロジェクト参照を通じて Wind Gust Library を使用します。
1. 空のプロジェクトを作成してプロジェクト名を設定します。
windGustFolder = fullfile(mainProject.RootFolder,"..","WindGustLibrary"); windGust = matlab.project.createProject(windGustFolder); windGust.Name = "Wind Gust Library";
2. data フォルダーと wind_gust_lib.slx ファイルを Wind Gust Library プロジェクトに追加します。
addFolderIncludingChildFiles(windGust,"data"); addFile(windGust,"wind_gust_lib.slx");
3. data フォルダーと Wind Gust Library プロジェクト ルート フォルダーを Wind Gust Library プロジェクト パスに追加します。これにより、Airframe Example プロジェクトまたは Wind Gust Library プロジェクトを参照する任意のプロジェクトが読み込まれるとファイルが利用可能になります。
addPath(windGust,"data");
addPath(windGust,windGust.RootFolder);4. Wind Gust Library プロジェクト ショートカットを作成します。
shortcut = addShortcut(windGust,"wind_gust_lib.slx"); shortcut.Group = "Top Level Model";
プロジェクト参照の追加
新しい Wind Gust Library プロジェクトをプロジェクト参照として Airframe Example プロジェクトに追加します。これにより Airframe Example プロジェクトで Wind Gust Library プロジェクトのファイルを表示、編集、および実行できます。
reload(mainProject); addReference(mainProject,windGust)
ans =
ProjectReference with properties:
Project: [1×1 matlab.project.Project]
File: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary"
StoredLocation: "../WindGustLibrary"
Type: "Relative"
メインのプロジェクト Airframe Example は "../refs/Wind Gust Library" に格納された Wind Gust Library を参照します。
ProjectReferences メソッドを使用して Wind Gust Library プロジェクトをクエリします。
mainProject.ProjectReferences(2).Project
ans =
Project with properties:
Details
Name: "Wind Gust Library"
Summary: ""
RootFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary"
DefinitionFilesType: FixedPathMultiFile
TopLevel: 0
Files
Files: [1×3 matlab.project.ProjectFile]
Shortcuts: [1×1 matlab.project.Shortcut]
Categories: [1×1 matlab.project.Category]
Dependencies: [1×1 digraph]
DependencyCacheFile: ""
Environment
ProjectStartupFolder: "/tmp/Bdoc_3342596_871047/tp2838f9ec/simulink/AirframeProjectWithOneReferencedProjectExample/WindGustLibrary"
StartupFiles: [1×0 string]
ShutdownFiles: [1×0 string]
PathFolders: [2×1 string]
TestFolders: [0×1 string]
ProjectDependencies: [1×0 matlab.project.Dependency]
ProjectReferences: [1×0 matlab.project.ProjectReference]
Simulink
StartSimulink: 0
RefreshSimulinkCustomizations: 0
SimulinkCacheFolder: ""
SimulinkCodeGenFolder: ""
Wind Gust Library プロジェクトは最上位プロジェクト (TopLevel: 0) ではありません。これは最上位プロジェクト Airframe Example (TopLevel: 1) によって参照されます。
プロジェクトを閉じる
プロジェクトを閉じてシャットダウン スクリプトを実行し、未保存のファイルを確認します。
close(mainProject)