이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
ModelAdvisor.ResultDetail.setData
클래스: ModelAdvisor.ResultDetail
네임스페이스: ModelAdvisor
Model Advisor 검사 결과를 특정 블록 또는 신호와 연결
구문
설명
ModelAdvisor.ResultDetail.setData(
는 Model Advisor 검사 결과 resultObj
,'Signal',signalHandle
)resultObj
를 Simulink 신호 signalHandle
와 연결합니다. 사용자 정의 검사 내에서 이 방법을 사용하여 검사를 위반하는 신호에 대한 정보를 반환할 수 있습니다.
입력 인수
resultObj
— Model Advisor 점검 결과
ModelAdvisor.ResultDetail
개체
Model Advisor 검사 결과는 ModelAdvisor.ResultDetail
객체로 지정됩니다.
blockID
— Simulink 블록
문자 배열 | string
Simulink 블록, 블록의 Simulink 식별자(SID)로 지정됩니다.
예: 'myModel/myBlock'
데이터형: char
| string
signalHandle
— Simulink 신호
double
Simulink 신호, 신호 핸들로 지정됩니다.
예: 280.0009
데이터형: double
예제
블록 위반에 대한 사용자 정의 모델 Advisor 검사 정의
블록 이름이 블록 아래에 나타나는지 확인하는 사용자 정의 Model Advisor 검사를 만듭니다.
모델을 엽니다.
openExample('AdvisorCustomizationExample')
모델을 작업 폴더에 저장합니다. 모델을 닫습니다.
편집 시 검사를 등록하려면 sl_customization
함수를 생성하세요. sl_customization
함수는 사용자 정의 관리자 개체라는 하나의 인수를 허용합니다. 사용자 정의 검사를 등록하려면 addModelAdvisorCheckFcn
방법을 사용하십시오. 이 메소드에 대한 입력은 검사 정의 함수에 대한 핸들입니다. 이 예에서는 defineDetailStyleCheck
가 검사 정의 기능입니다. sl_customization
함수를 생성하고 작업 폴더에 저장합니다.
function sl_customization(cm)
cm.addModelAdvisorCheckFcn(@defineDetailStyleCheck);
검사 정의 기능을 만듭니다. 이 예에서는 defineDetailStyleCheck.m
이라는 함수 파일을 만듭니다. 다음 코드 defineDetailStyleCheck.m
을 복사하고 함수를 작업 폴더에 저장합니다.
function defineDetailStyleCheck % Create a ModelAdvisor.Check object and set the properties. rec = ModelAdvisor.Check('com.mathworks.sample.detailStyle'); rec.Title = 'Check whether block names appear below blocks'; rec.TitleTips = 'Check position of block names'; rec.setCallbackFcn(@DetailStyleCallback,'None','DetailStyle'); % Create a ModelAdvisor.Action object for setting a fix operation. myAction = ModelAdvisor.Action; myAction.setCallbackFcn(@ActionCB); myAction.Name='Make block names appear below blocks'; myAction.Description='Click the button to place block names below blocks'; rec.setAction(myAction); % Publish the check to the Demo group. mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec, 'Demo'); end % ----------------------------- % This callback function uses the DetailStyle CallbackStyle type. % ----------------------------- function DetailStyleCallback(system, CheckObj) % Get the Model Advisor object. mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); % Find the blocks whose names do not appear below the block. violationBlks = find_system(system, 'Type','block',... 'NamePlacement','alternate',... 'ShowName', 'on'); if isempty(violationBlks) ElementResults = ModelAdvisor.ResultDetail; ElementResults.ViolationType = 'info'; ElementResults.Description = 'Identify blocks where the name is not displayed below the block.'; ElementResults.Status = 'All blocks have names displayed below the block.'; mdladvObj.setCheckResultStatus(true); else for i=1:numel(violationBlks) ElementResults(1,i) = ModelAdvisor.ResultDetail; end for i=1:numel(ElementResults) ModelAdvisor.ResultDetail.setData(ElementResults(i), 'SID',violationBlks{i}); ElementResults(i).Description = 'Identify blocks where the name is not displayed below the block.'; ElementResults(i).Status = 'The following blocks have names that do not display below the block:'; ElementResults(i).RecAction = 'Change the location such that the block name is below the block.'; end mdladvObj.setCheckResultStatus(false); mdladvObj.setActionEnable(true); end CheckObj.setResultDetails(ElementResults); end % ----------------------------- % This action callback function changes the location of the block names. % ----------------------------- function result = ActionCB(taskObj) mdladvObj = taskObj.MAObj; checkObj = taskObj.Check; resultDetailObjs = checkObj.ResultDetails; for i=1:numel(resultDetailObjs) block=Simulink.ID.getHandle(resultDetailObjs(i).Data); set_param(block,'NamePlacement','normal'); end result = ModelAdvisor.Text('Changed the location such that the block name is below the block.'); mdladvObj.setActionEnable(false); end
검사 정의 기능에는 검사 작업과 수정 사항을 정의하는 ModelAdvisor.Check
및 ModelAdvisor.Action
개체가 포함되어 있습니다. 코드의 이러한 측면에 대한 자세한 내용은 Fix a Model to Comply with Conditions that You Specify with the Model Advisor를 참조하세요.
defineDetailStyleCheck
함수에는 DetailStyleCallback
콜백 함수가 포함되어 있습니다. 이름이 아래에 표시되지 않는 블록을 반환하기 위해 DetailStyleCallback
함수는 find_system
함수를 사용합니다.
violationBlks
가 비어 있으면 코드는 하나의 ModelAdvisor.ResultDetail
객체인 ElementResults
를 생성합니다. ElementResults
는 Model Advisor에 나타나는 검사 통과에 대한 정보를 지정합니다.
find_system
함수가 검사를 위반하는 블록 목록을 반환하는 경우 ElementResults
는 ModelAdvisor.ResultDetail
개체의 배열입니다. 배열에는 검사를 위반하는 각 블록에 대해 하나의 개체가 포함됩니다. 각 객체에는 Model Advisor에 나타나는 블록에 대한 정보가 포함되어 있습니다.
Model Advisor를 새로 고쳐 경로에 대한 새로운 검사로 캐시를 업데이트합니다.
Advisor.Manager.refresh_customizations
AdvisorCustomizationExample
모델을 엽니다.
모델링 탭을 클릭하고 모델 어드바이저을 선택하여 Model Advisor를 엽니다.
왼쪽 창에서 제품별 > 데모 > Check whether block names appear below을 선택하고 검사 실행를 클릭합니다.
경고를 해결하려면 수정를 클릭하세요.
신호 위반에 대한 사용자 정의 편집 시 검사 정의
출력 블록에 연결되는 신호에 레이블이 있는지 확인하는 사용자 정의 편집 시 검사를 만듭니다.
모델을 엽니다.
openExample('AdvisorCustomizationExample')
모델을 작업 폴더에 저장합니다. 모델을 닫습니다.
사용자 정의 편집 시 검사를 등록하려면 sl_customization
함수를 생성하고 작업 폴더에 저장하세요.
function sl_customization(cm)
cm.addModelAdvisorCheckFcn(@defineCheck);
검사 정의 기능을 만듭니다. 함수 내에서 ModelAdvisor.Check
객체를 생성하고 검사 ID를 입력 인수로 지정합니다. 그런 다음 ModelAdvisor.Check
Title
및 CallbackHandle
속성을 지정합니다. CallbackHandle
속성은 편집 시 검사를 정의하기 위해 생성하는 클래스의 이름입니다. 이 예에서 MyEditTimeChecks
는 패키지 이름이고 SignalLabel
은 클래스 이름입니다. 그런 다음 Model Advisor의 새 폴더에 검사를 게시합니다. 이 예에서 폴더 이름은 Demo: Edit-Time Checks
입니다. defineCheck
함수를 만들고 다음 코드를 포함합니다. defineCheck
함수를 작업 폴더에 저장합니다.
function defineCheck rec = ModelAdvisor.Check("advisor.edittimecheck.SignalLabel"); rec.Title = 'Check that signals have labels if they are to propagate those labels'; rec.CallbackHandle = 'MyEditTimeChecks.SignalLabels'; mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec,'DEMO: Edit-Time Checks');
ModelAdvisor.EdittimeCheck
추상 기본 클래스에서 파생되는 클래스를 만듭니다. 이 예에서는 SignalLabel.m
라는 클래스 파일을 만듭니다. 다음 코드를 SignalLabel.m
파일에 복사하고 +MyEditTimeChecks
폴더에 저장합니다.
classdef SignalLabels < ModelAdvisor.EdittimeCheck methods function obj=SignalLabels(checkId) obj=obj@ModelAdvisor.EdittimeCheck(checkId); obj.traversalType = edittimecheck.TraversalTypes.BLKITER; end function violation = blockDiscovered(obj, blk) violation = []; ports = get_param(blk,'Ports'); lh = get_param(blk, 'LineHandles'); if strcmp(get_param(blk,'BlockType'),'Outport') for j = 1 : ports(1) if lh.Inport(j) ~= -1 % failure case: no connection allsources = get_param(lh.Inport(j),'SrcPortHandle'); hiliteHandle = get_param(lh.Inport(j), 'DstPortHandle'); if (isempty(allsources) ~= 0) || (isempty(find(allsources==-1,1)) ~= 0) lh_obj = get_param(lh.Inport(j),'Object'); if isempty(lh_obj.Name) if strcmp(lh_obj.signalPropagation,'off') == 1 allsources_parent = get_param(allsources,'Parent'); if strcmp(get_param(allsources_parent,'BlockType'),'Inport') buscreator_outputs = get_param(allsources_parent,'IsBusElementPort'); else buscreator_outputs = 'off'; end if ~strcmp(buscreator_outputs,'on') violation = ModelAdvisor.ResultDetail; ModelAdvisor.ResultDetail.setData(violation, 'Signal',hiliteHandle); violation.Description ='The model does not adhere to the signal label modeling guideline.'; violation.CheckID = obj.checkId; violation.Title = 'Signal Label Missing'; violation.Information = 'This check verifies the presence of signal label.'; violation.Status = 'The following signals do not have a label:'; end end end end end end end end end end
ModelAdvisor.EdittimeCheck
클래스의 코드에 대한 자세한 내용은 Define Edit-Time Checks to Comply with Conditions That You Specify with the Model Advisor를 참조하세요.
blockDiscovered
방법에는 검사 위반을 정의하는 알고리즘이 포함되어 있습니다. Model Advisor에만 나타나는 사용자 정의 검사와 달리 이 알고리즘에는 find_system
함수가 포함되어 있지 않습니다. blockDiscovered
방법은 블록 핸들을 입력으로 사용하고 모델을 탐색하므로 사용자 정의 편집 시 검사를 위해 find_system
기능이 필요하지 않습니다.
검사를 위반하는 각 모델 요소에 대해 코드는 ModelAdvisor.ResultDetail
객체를 생성합니다. 이 예에서는 위반이 신호에 있기 때문에 검사에서는 블록의 라인 핸들에 있는 매개변수를 사용해야 합니다. 위반이 있는 신호를 찾으려면 LineHandles
옵션을 지정해야 합니다. 특히 Outport 블록에 연결되는 신호의 경우 이 알고리즘은 Name
신호 매개변수에 값이 있는지 확인합니다. 그런 다음 위반이 신호에 있기 때문에 알고리즘은 Type
속성 값이 Signal
로 설정된 위반 객체를 생성하여 신호를 강조 표시합니다.
Model Advisor를 새로 고쳐 경로에 대한 새로운 검사로 캐시를 업데이트합니다.
Advisor.Manager.refresh_customizations
AdvisorCustomizationExample
모델을 엽니다.
모델링 탭을 클릭하고 모델 어드바이저 > 구성 편집기을 선택하여 Model Advisor 구성 편집기를 엽니다.
DEMO: Edit Time Checks 폴더를 제외한 모든 폴더를 삭제하여 사용자 정의 편집 시 검사로 구성된 사용자 정의 구성을 만듭니다.
구성을 my_config.json
로 저장합니다. 이 구성을 기본값으로 설정하라는 메시지가 나타나면 아니요를 클릭합니다.
Model Advisor 구성 편집기를 닫습니다.
모델링 탭을 클릭하고 모델 어드바이저 > 편집 시 검사를 선택하여 사용자 정의 구성을 my_config.json
파일로 설정합니다. 구성 매개변수 대화 상자에서 모델 어드바이저 구성 파일 매개변수에 구성 파일 경로를 지정합니다.
편집 시 검사 매개변수를 선택하여 편집 시 검사를 활성화합니다. 모델 구성 매개변수 대화 상자를 닫습니다.
편집 시간 경고를 보려면 노란색으로 강조 표시된 신호를 클릭하세요. Outport 블록에 연결되는 신호에는 라벨이 없기 때문에 경고가 발생합니다.
이 이미지는 Model Advisor 보고서의 ModelAdvisor.ResultDetail
속성을 보여줍니다.
버전 내역
R2018b에 개발됨R2021b: 정적 메소드 ModelAdvisor.ResultDetail.setData
를 사용하여 Model Advisor 결과 세부 데이터 설정
ModelAdvisor.ResultDetail
클래스의 setData
메서드는 정적 메서드입니다. 클래스 이름, 점(.
), 메서드 이름을 차례로 사용하여 메서드를 호출합니다.
ModelAdvisor.ResultDetail.setData(ElementResults
,args,...)
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 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)