addLabel
プロジェクト ファイルにラベルを追加
説明
addLabel(
は、指定されたカテゴリの指定されたラベルを指定されたファイルに追加します。file
,categoryName
,labelName
)
addLabel(
は、指定されたテキストまたは数値データをもつラベルを追加します。組み込みのラベルは読み取り専用であるため、ラベル データを追加することはできません。file
,categoryName
,labelName
,labelData
)
例
プロジェクト ファイルへのラベルの追加
プロジェクト Times Table App を開きます。currentProject
を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
名前を指定してファイルを取得します。
myfile = findFile(proj,"source/timesTableGame.m")
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×1 matlab.project.Label] Revision: "286043ae7ee557100902fb645a6c97eca5d50472" SourceControlStatus: Unmodified
ファイルの Labels
プロパティを取得して、既存のラベルを表示します。
myfile.Labels
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Design" CategoryName: "Classification"
ラベル "Artifact"
をカテゴリ "Classification"
のファイルに追加します。
addLabel(myfile,"Classification","Artifact")
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Artifact" CategoryName: "Classification"
現在は、2 つのラベル (元のラベルと追加されたラベル) があります。追加されたラベルのみを表示するには、Labels
プロパティにインデックスを付けます。
reviewlabel = myfile.Labels(1)
reviewlabel = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Artifact" CategoryName: "Classification"
ファイルから新規ラベルを削除します。現在、ファイルに付けられているラベルは 1 つのみです。
removeLabel(myfile,reviewlabel) myfile
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×0 matlab.project.Label] Revision: "286043ae7ee557100902fb645a6c97eca5d50472" SourceControlStatus: Unmodified
ファイルのサブセットへのラベルの追加
"Classification"
カテゴリのラベル "Utility"
をファイル拡張子 .m
をもつプロジェクト内のすべてのファイルに追加します。
プロジェクト Times Table App を開きます。currentProject
を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
ファイル一覧を取得します。
files = proj.Files;
各ファイルに対して作業を繰り返します。ファイル拡張子のみを取得するには、関数 fileparts
を使用して最後の部分を取り出します。ファイルに .m
という拡張子が含まれる場合、ラベル "Utility"
を追加します。
for fileIndex = 1:numel(files) file = files(fileIndex); [~, ~, fileExtension] = fileparts(file.Path); if strcmp(fileExtension,".m") addLabel(file,"Classification","Utility"); end end
プロジェクトの [ファイル] ビューで、[Classification] 列に utilities
フォルダーの各 .m
ファイルに対してラベル "Utility"
が表示されます。
ファイルへのラベルとラベル データの追加
ラベル カテゴリ "Review"
およびラベル "To Review" を作成し、そのラベルとラベル データをファイルに追加します。組み込みのラベルは読み取り専用であるため、ラベル データを追加することはできません。
プロジェクト Times Table App を開きます。currentProject
を使用して、現在読み込まれているプロジェクトからプロジェクト オブジェクトを作成します。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
新しいカテゴリ "Review"
を作成します。
createCategory(proj,"Review","char");
新しいカテゴリに対して、"To Review"
ラベルを作成します。
reviewCategory = findCategory(proj,"Review"); createLabel(reviewCategory,"To Review");
名前を指定してファイルを取得します。
myfile = findFile(proj,"source/timesTableGame.m")
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×1 matlab.project.Label] Revision: "c7603d5dd71a40484974c3f1c45d839819b7b061" SourceControlStatus: Unmodified
ファイルに "To Review"
ラベル、およびラベル データの文字ベクトルを追加します。
addLabel(myfile,"Review","To Review","Whole team design review")
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'char' Data: 'Whole team design review' Name: "To Review" CategoryName: "Review"
プロジェクトの [ファイル] ビューで timesTableGame.m
ファイルに対し、[Review] 列にラベル データとラベル "To Review"
が表示されます。
あるいは、Data
プロパティを使用してラベル データを設定または変更できます。
mylabel = myfile.Labels(1);
mylabel.Data = "Final review";
入力引数
file
— ラベルを付けるファイル
ProjectFile
オブジェクト
ラベルを付けるファイル。ProjectFile
オブジェクトとして指定します。ProjectFile
オブジェクトを取得するには、プロジェクトの Files プロパティ (proj.Files
) を調べるか、関数 findFile
を使用して名前でファイルを検索します。ファイルはプロジェクト内になければなりません。
categoryName
— ラベルのカテゴリ名
文字ベクトル | string スカラー
ラベルのカテゴリ名。文字ベクトルまたは string スカラーとして指定します。
labelName
— ラベル名
文字ベクトル | string スカラー | LabelDefinition
オブジェクト
追加するラベルの名前。文字ベクトル、string スカラー、または file.Label
プロパティや関数 findLabel
によって返される LabelDefinition
オブジェクトとして指定します。プロジェクトに存在しない新規ラベル名を指定することができます。
labelData
— ラベルに追加するデータ
文字ベクトル | string スカラー | 数値
ラベルに追加するデータ。文字ベクトル、string スカラー、または数値として指定します。データ型は、ラベルの定義によって異なります。その DataType
プロパティを調べるには、file.Label
または関数 findLabel
を使用してラベルを取得します。
バージョン履歴
R2019a で導入
参考
currentProject
| openProject
| createLabel
| findFile
| findLabel
| removeLabel
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)