Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

coder.ClassType 클래스

네임스페이스: coder
슈퍼클래스: coder.ArrayType

입력 사양에 허용되는 MATLAB 클래스 집합 표현

설명

coder.ClassType의 객체는 생성 코드에서 허용하는 값 클래스 객체를 지정합니다. 이 클래스의 객체는 fiaccel 함수의 -args 옵션에만 사용하십시오. 생성된 MEX 함수에 대한 입력값으로 전달하지 마십시오.

생성

t = coder.typeof(classObject)classObject에 대한 coder.ClassType 객체를 생성합니다.

t = coder.newtype(className)className 클래스의 객체에 대한 coder.ClassType 객체를 생성합니다.

참고

Coder Type Editor를 사용하여 대화형 방식으로 coder.Type 객체를 생성하고 편집할 수 있습니다. Create and Edit Input Types by Using the Coder Type Editor 항목을 참조하십시오.

입력 인수

모두 확장

coder.ClassType 객체를 생성할 값 클래스 객체. 이 입력값은 값 클래스의 객체로 평가되는 표현식입니다.

MATLAB 경로에 있는 값 클래스 정의 파일의 이름으로, 문자형 벡터 또는 string형 스칼라로 지정됩니다.

속성

값 클래스 객체 vcoder.typeof에 전달하여 coder.ClassType 객체 t를 생성할 경우 tv와 동일한 속성을 가지며 Constant 특성은 false로 설정됩니다.

마찬가지로, 값 클래스 객체 v의 이름을 coder.newtype에 전달하여 coder.ClassType 객체 t를 생성할 경우 tv와 동일한 속성을 가지며 Constant 특성은 false로 설정됩니다.

예제

모두 축소

이 예제에서는 작업 공간에 있는 샘플 객체에 기반하여 type 객체를 만드는 방법을 보여줍니다.

값 클래스 myRectangle을 만듭니다.

type myRectangle.m
classdef myRectangle
    properties
        length;
        width;
    end
    methods
        function obj = myRectangle(l,w)
            if nargin > 0
                obj.length = l;
                obj.width = w;
            end
        end
        function area = calcarea(obj)
            area = obj.length * obj.width;
        end
    end
end

myRectangle의 객체를 입력값으로 받는 함수를 만듭니다.

type getarea.m
function z = getarea(r)
%#codegen
z = calcarea(r);
end

myRectangle의 객체를 만듭니다.

v = myRectangle(1,2)
v = 
  myRectangle with properties:

    length: 1
     width: 2

v에 기반하여 coder.ClassType 객체를 만듭니다.

t = coder.typeof(v)
t = 
coder.ClassType
   1×1 myRectangle   
      Properties : 
      	length : 1×1 double
      	width  : 1×1 double

coder.typeofv와 동일한 속성 이름과 유형을 갖는 coder.ClassType 객체를 만듭니다.

getarea에 대한 코드를 생성합니다. coder.ClassType 객체 t-args 옵션에 전달하여 입력 유형을 지정합니다.

codegen getarea -args {t} -report
Code generation successful: To view the report, open('codegen/mex/getarea/html/report.mldatx')

이 예제에서는 coder.newtype을 사용하여 값 클래스 mySquare의 객체에 대한 coder.ClassType 객체를 만드는 방법을 보여줍니다.

하나의 속성 side를 갖는 값 클래스 mySquare를 만듭니다.

type mySquare.m
classdef mySquare
    properties
        side;
    end
    methods
        function obj = mySquare(val)
            if nargin > 0
                obj.side = val;
            end
        end
        function a = calcarea(obj)
            a = obj.side * obj.side;
        end
    end
end

속성값을 할당하지 않고 mySquare에 대한 coder.ClassType 유형을 만듭니다.

t = coder.newtype('mySquare')
t = 
coder.ClassType
   1×1 mySquare -- class with no properties

tmySquare의 속성을 갖도록, t.Properties를 사용하여 side의 유형을 지정합니다.

t.Properties.side = coder.typeof(2)
t = 
coder.ClassType
   1×1 mySquare   
      Properties : 
      	side : 1×1 double

  • coder.ClassType을 만든 후에 속성의 유형을 수정할 수 있습니다. 예를 들어, 다음과 같이 객체 tprop1 속성 유형과 prop2 속성 유형을 수정합니다.

    t = coder.typeof(myClass)
    t.Properties.prop1 = coder.typeof(int16(2));
    t.Properties.prop2 = coder.typeof([1 2 3]);

  • coder.ClassType 객체를 만든 후에 속성을 추가할 수 있습니다. 예를 들어, 다음과 같이 객체 tnewprop1 속성과 newprop2 속성을 추가합니다.

    t = coder.typeof(myClass)
    t.Properties.newprop1 = coder.typeof(int8(2));
    t.Properties.newprop2 = coder.typeof([1 2 3]);

  • 코드 생성 시, codegen 함수에 전달하는 coder.ClassType 객체의 속성은 클래스 정의 파일에 있는 속성과 일치해야 합니다. 그러나 클래스 정의 파일에 사용자의 코드가 사용하지 않는 속성이 있는 경우 coder.ClassType 객체는 이러한 속성을 포함할 필요가 없습니다. 코드 생성기는 사용자의 코드가 사용하지 않는 속성을 무시합니다.

버전 내역

R2017a에 개발됨