이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
명령줄에서 모델 구성하기
코드 생성기는 생성된 코드를 사용자 지정할 수 있도록 모델 파라미터를 제공합니다. 코드 생성을 어떻게 사용하고 상호작용하느냐에 따라 구성 설정을 결정하게 됩니다. 디버깅, 추적성, 코드 효율성 및 안전 예방 조치 측면에서 자신의 요구 사항에 가장 잘 맞는 구성을 선택하십시오.
원하는 구성을 결정한 후에는 MATLAB® 스크립트를 사용하여 모델 구성 과정을 자동화하는 것이 일반적입니다.
이 예제는 다음을 설명합니다:
구성 파라미터 활용 개념
코드 생성 옵션을 이해하기 위한 설명서
모델 구성을 자동화하는 툴 및 스크립트
구성 파라미터 워크플로
구성 파라미터에 대한 워크플로에는 단일 모델 내의 지속성 또는 여러 모델에 걸친 지속성을 포함하는 다양한 유형이 있습니다. 사용자의 필요에 따라 구성 세트를 복사본이나 참조 형태로 사용할 수 있습니다. 이 예제는 모델의 활성 구성 세트를 직접 다루는 기본 단계를 보여줍니다. 구성 세트의 기능 및 워크플로에 대한 자세한 설명은 Simulink® 문서의 Manage Configuration Sets for a Model 항목을 참조하십시오.
구성 세트의 기본 개념
모델을 메모리에 불러옵니다.
model='ThrottleControl';
load_system(model)
모델의 활성 구성 세트를 가져옵니다.
cs = getActiveConfigSet(model);
Simulink® Coder™는 코드 생성 옵션 중 일부만 제공합니다. Simulink® Coder™를 사용하는 경우, Generic Real-Time (GRT) 타깃을 선택하십시오.
switchTarget(cs,'grt.tlc',[]);
Embedded Coder®는 코드 생성 옵션의 전체 세트를 제공합니다. Embedded Coder®를 사용하는 경우, Embedded Real-Time (ERT) 타깃을 선택하십시오.
switchTarget(cs,'ert.tlc',[]);
GRT 및 ERT 기반 타깃을 위해 구축된 모델의 구성을 자동화하려면, 구성 세트의 IsERTTarget 특성을 활용하면 유용합니다.
isERT = strcmp(get_param(cs,'IsERTTarget'),'on');
모델이나 구성 세트를 통해 코드 생성 옵션을 설정할 수 있습니다. 이 예제는 모델을 통해 간접적으로 옵션을 가져오고 설정합니다.
deftParamBehvr = get_param(model,'DefaultParameterBehavior'); % Get set_param(model,'DefaultParameterBehavior',deftParamBehvr) % Set
이 예제는 구성 세트를 통해 옵션을 직접 가져오고 설정합니다.
if isERT lifespan = get_param(cs,'LifeSpan'); % Get LifeSpan set_param(cs,'LifeSpan',lifespan) % Set LifeSpan end
구성 옵션 요약
코드 생성 옵션의 전체 목록은 디버깅, 추적성, 코드 효율성 및 안전 예방 조치 측면에서의 장단점과 함께 문서화되어 있습니다. Simulink® Coder™에 대해서는 Recommended Settings Summary for Model Configuration Parameters의 Simulink® Coder™ 버전을 참조하십시오. Embedded Coder®에 대해서는 Recommended Settings Summary for Model Configuration Parameters (Embedded Coder)의 Embedded Coder® 버전을 참조하십시오.
코드 생성 어드바이저를 사용하여 목표에 최적화된 모델 구성을 확보하십시오. '목표 설정' 대화 상자에서 목표를 설정하고 우선순위를 지정할 수 있습니다.

코드 생성 어드바이저를 활용한 애플리케이션 목표에서 코드 생성 어드바이저에 대한 문서를 확인할 수 있습니다. Embedded Coder®에 관한 추가 문서는 코드 생성 어드바이저를 사용하여 코드 생성 목표에 맞게 모델 구성하기 (Embedded Coder)에서 확인할 수 있습니다.
파라미터 구성 스크립트
Simulink® Coder™는 사용자의 애플리케이션을 개발할 때 출발점으로 활용할 수 있는 구성 스크립트 예제를 제공합니다. 가장 관련성이 높은 GRT 및 ERT 코드 생성 옵션 목록은 rtwconfiguremodel.m에 포함되어 있습니다.
또는, 구성 세트 saveAs 함수를 사용하여 모델 파라미터의 전체 목록이 포함된 MATLAB 함수를 생성할 수도 있습니다.
% Save the model's configuration parameters to file 'MyConfig.m'. saveAs(cs,'MyConfig') % Display the first 50 lines of MyConfig.m. dbtype MyConfig 1:50
1 function cs = MyConfig()
2 % MATLAB function for configuration set generated on 20-Apr-2026 08:51:05
3 % MATLAB version: 26.1.0.3212433 (R2026a) Update 1
4
5 cs = Simulink.ConfigSet;
6
7 % Original configuration set version: 26.0.0
8 if cs.versionCompare('26.0.0') < 0
9 error('Simulink:MFileVersionViolation', 'The version of the target configuration set is older than the original configuration set.');
10 end
11
12 % Character encoding: UTF-8
13
14 % Do not change the order of the following commands. There are dependencies between the parameters.
15 cs.set_param('Name', 'Configuration'); % Name
16 cs.set_param('Description', ''); % Description
17
18 % Original configuration set target is ert.tlc
19 cs.switchTarget('ert.tlc','');
20
21 cs.set_param('HardwareBoard', 'None'); % Hardware board
22
23 cs.set_param('TargetLang', 'C'); % Language
24
25 cs.set_param('CodeInterfacePackaging', 'Nonreusable function'); % Code interface packaging
26
27 cs.set_param('GenerateAllocFcn', 'off'); % Use dynamic memory allocation for model initialization
28
29 cs.set_param('Solver', 'FixedStepDiscrete'); % Solver
30
31 % Solver
32 cs.set_param('StartTime', '0.0'); % Start time
33 cs.set_param('StopTime', '10.0'); % Stop time
34 cs.set_param('SolverName', 'FixedStepDiscrete'); % Solver
35 cs.set_param('SolverType', 'Fixed-step'); % Type
36 cs.set_param('SampleTimeConstraint', 'Unconstrained'); % Periodic sample time constraint
37 cs.set_param('FixedStep', '.001'); % Fixed-step size (fundamental sample time)
38 cs.set_param('EnableFixedStepZeroCrossing', 'off'); % Enable zero-crossing detection for fixed-step simulation
39 cs.set_param('ConcurrentTasks', 'off'); % Allow tasks to execute concurrently on target
40 cs.set_param('EnableMultiTasking', 'on'); % Treat each discrete rate as a separate task
41 cs.set_param('AllowMultiTaskInputOutput', 'off'); % Allow multiple tasks to access inputs and outputs
42 cs.set_param('PositivePriorityOrder', 'off'); % Higher priority value indicates higher task priority
43 cs.set_param('AutoInsertRateTranBlk', 'off'); % Automatically handle rate transition for data transfer
44
45 % Data Import/Export
46 cs.set_param('Decimation', '1'); % Decimation
47 cs.set_param('LoadExternalInput', 'off'); % Load external input
48 cs.set_param('SaveFinalState', 'off'); % Save final state
49 cs.set_param('LoadInitialState', 'off'); % Load initial state
50 cs.set_param('LimitDataPoints', 'on'); % Limit data points
생성된 파일의 각 파라미터 설정에는 구성 파라미터 대화 상자의 해당 파라미터 문자열에 대한 주석이 포함되어 있습니다.
요약
Simulink는 시뮬레이션 및 코드 생성을 위한 모델 구성을 자동화할 수 있는 다양한 MATLAB 함수 세트를 제공합니다. Simulink Coder 및 Embedded Coder®는 코드 생성에 특화된 추가 기능을 제공합니다. 코드 생성 어드바이저는 우선순위가 지정된 일련의 목표를 바탕으로 모델 구성을 최적화합니다. 구성 세트의 saveAs 함수를 사용하여 최적의 구성을 MATLAB 파일에 저장한 다음, 여러 모델과 프로젝트에서 재사용할 수 있습니다.